Aller au contenu
Français

LWWMapOptions

Ce contenu n’est pas encore disponible dans votre langue.

LWWMapOptions<K> = object

Defined in: src/crdt/LWWMap.ts:35

Map of last-writer-wins registers. Each entry carries its own (value, timestamp, replicaId) tuple, and per-key conflict resolution is identical to LWWRegister: higher timestamp wins, ties broken by replica id.

Pattern fits: per-key feature flags, per-user options, profile fields where one writer at a time is normal but eventual consistency across replicas matters.

const m = LWWMap.empty<string, string>() .put(‘a’, ‘theme’, ‘dark’, 100) .put(‘b’, ‘theme’, ‘light’, 200); // newer wins m.get(‘theme’) // → ‘light’

Removal is implemented as a tombstone — remove(replica, key, timestamp) writes a null-valued register at the given timestamp. On merge, a newer tombstone wins over an older value (key disappears) and a newer value wins over an older tombstone (key reappears). get() returns undefined for tombstoned keys.

Wall-clock pitfall. Default timestamp is Date.now() — see LWWRegister’s class doc for the standard caveats. Pass an explicit timestamp for HLC / Lamport-style semantics.

Element identity. Same JSON-stringify default + identity override pattern as GSet / ORSet. Pass { identity: k => ... } for non-JSON keys.

K

readonly optional identity?: (k) => string

Defined in: src/crdt/LWWMap.ts:36

K

string