CRDTMap is a collaborative map where each key holds its own independent CRDT (GCounter, PNCounter, ORSet, LwwRegister, or Presence). The type of each key is fixed at first write. Merge is performed per-key — keys are independent and never conflict with each other.
Use this when you need a structured document with multiple independent fields, each with their own conflict resolution semantics.
Basic usage
Per-key CRDT types
Each key is permanently bound to its CRDT type at first write. Sending an operation of the wrong type to an existing key is rejected by the server.LWW-Register key
GCounter key
PNCounter key
ORSet key
API
| Method | Description |
|---|---|
value() | Returns snapshot of the full map Record<string, unknown> |
get(key) | Returns the current value at key, or undefined |
onChange(fn) | Subscribe to any change — returns unsubscribe function |
lwwSet(key, value) | Write a LWW-Register value |
incrementCounter(key, amount?) | Increment a GCounter key (default 1) |
incrementPNCounter(key, amount?) | Increment a PNCounter key (default 1) |
decrementPNCounter(key, amount?) | Decrement a PNCounter key (default 1) |
orsetAdd(key, element, tag) | Add an element to an ORSet key |
orsetRemove(key, element, knownTags) | Remove an element from an ORSet key |