Map

Loro’s Map uses LWW (Last-Write-Wins) semantics. When concurrent edits conflict, it compares Lamport logic timestamps to determine the winner.

Map slot conflicts are still resolved by LWW. If the value at a key is a child container, regular child containers have operation-derived identities, so two peers that create a child at the same key can create two different children. If the child should be shared by logical key, use a mergeable child container:

const body = doc.getMap("notes").ensureMergeableText(noteId);
body.insert(0, "Hello");

Here is how to use it:

const  = new ();
.("0");
const  = new ();
.("1");
 
const  = .("map");
const  = .("map");
 
.("a", 1);
const  = .("a", new ());
.(0, "Hi");
 
.(.()); // OUTPUT: { map: { a: 1 } }
.(.()); // OUTPUT: { map: { a: "Hi" } }
 
.(.({ : "snapshot" }));
.(.({ : "snapshot" }));
 
// docB wins because it has the larger peerId, thus the larger logical timestamp
.(.()); // OUTPUT: { map: { a: "Hi" } }
.(.()); // OUTPUT: { map: { a: "Hi" } }

Note: When calling map.set(key, value) on a LoroMap, if map.get(key) already returns value, the operation will be a no-op (no operation recorded).