Readonly
idGet the id of this container.
Readonly
lengthGet the length of list.
Delete all elements in the list.
Get the value at the index. If the value is a container, the corresponding handler will be returned.
Get the attached container associated with this.
Returns an attached Container
that equals to this or created by this, otherwise undefined
.
Get the cursor position at the given pos.
When expressing the position of a cursor, using "index" can be unstable because the cursor's position may change due to other deletions and insertions, requiring updates with each edit. To stably represent a position or range within a list structure, we can utilize the ID of each item/character on List CRDT or Text CRDT for expression.
Loro optimizes State metadata by not storing the IDs of deleted elements. This approach complicates tracking cursors since they rely on these IDs. The solution recalculates position by replaying relevant history to update cursors accurately. To minimize the performance impact of history replay, the system updates cursor info to reference only the IDs of currently present elements, thereby reducing the need for replay.
Optional
side: SideGet the shallow value of the list.
Unlike toJSON()
which recursively resolves all containers to their values,
getShallowValue()
returns container IDs as strings for any nested containers.
const doc = new LoroDoc();
doc.setPeerId("1");
const list = doc.getList("list");
list.insert(0, 1);
list.insert(1, "two");
const subList = list.insertContainer(2, new LoroList());
subList.insert(0, "sub");
list.getShallowValue(); // [1, "two", "cid:2@1:List"]
list.toJSON(); // [1, "two", ["sub"]]
Whether the container is attached to a document.
If it's detached, the operations on the container will not be persisted.
Check if the container is deleted
"List"
Get the parent container.
undefined
.Pop a value from the end of the list.
Get elements of the list. If the value is a child container, the corresponding
Container
will be returned.
Get elements of the list. If the type of a element is a container, it will be resolved recursively.
The handler of a list container.
Learn more at https://loro.dev/docs/tutorial/list