You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the documents we're using Loro with has a value that may be null or a container like LoroMap. When the value is null and we try to initialize it with a container using getOrCreateContainer, Loro throws an exception.
It is possible to avoid this error by first checking if the stored value is null and using setContainer in that case. However, I think it would be more ergonomic if getOrCreateContainer treated null values the same way as the field not being initialized at all.
loro-crdt version: 1.1.4
Example
import{LoroDoc,LoroMap}from"loro-crdt";constdoc=newLoroDoc();constroot=doc.getMap("root");// No key -- okroot.getOrCreateContainer("key",newLoroMap());doc.commit();console.log(doc.toJSON());// Set to null -- okroot.set("key",null);doc.commit();console.log(doc.toJSON());// Key is null, create a containertry{root.getOrCreateContainer("key",newLoroMap());}catch(e){console.error(e);// Invalid argument (Expected value type Map but found Value(Null))}// Avoids the error but defeats the purpose of getOrCreateContainerletinner=root.get("key");if(!inner){inner=root.setContainer("key",newLoroMap());}console.log(doc.toJSON())
The text was updated successfully, but these errors were encountered:
One of the documents we're using Loro with has a value that may be
null
or a container likeLoroMap
. When the value isnull
and we try to initialize it with a container usinggetOrCreateContainer
, Loro throws an exception.It is possible to avoid this error by first checking if the stored value is
null
and usingsetContainer
in that case. However, I think it would be more ergonomic ifgetOrCreateContainer
treated null values the same way as the field not being initialized at all.loro-crdt
version:1.1.4
Example
The text was updated successfully, but these errors were encountered: