Map
Loro’s Map uses LWW (Last-Write-Wins) semantics. When concurrent edits conflict, it compares Lamport logic timestamps to determine the winner.
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, ifmap.get(key)
already returnsvalue
, the operation will be a no-op (no operation recorded).