LiveMap is a synchronized key/value data structure that stores primitive values, such as numbers, strings, booleans, binary data, JSON-serializable objects or arrays and other live object types. It ensures that all updates are correctly applied and synchronized across clients in realtime, automatically resolving conflicts with last-write-wins (LWW) semantics.
You interact with LiveMap through a PathObject or by obtaining a specific Instance.
Create a map
Create aLiveMap using the LiveMap.create() static method and assign it to a path:
LiveMap.create() returns a value type that describes the initial data for a new map. The actual object is created when assigned to a path. Each assignment creates a distinct object with its own unique ID:
Get map values
Access aLiveMap through a PathObject for path-based operations, or obtain a specific Instance to work with the underlying object directly. Use the get() method to navigate to entries within the map.
What you can do with the result depends on the type of value stored in the entry:
- For entries containing primitive values or
LiveCounterobjects, use thevalue()method to get the current value. - For entries containing nested
LiveMapobjects, useget()to continue navigating deeper into the structure.
Get compact object
Get a JavaScript object representation of the map using thecompact() or compactJson() methods:
Set map values
Set a value for a key in the map using theset() method. You can store primitive values or other live object types:
Remove a key
Remove a key from the map using theremove() method:
Get map size
Get the number of keys in the map using thesize() method:
Enumerate entries
Iterate over the map’s keys, values, or entries. When iterating using aPathObject, values are returned as a PathObject for the nested path. When iterating using an Instance, values are returned as an Instance for the entry:
Batch multiple operations
Group multiple map operations into a single atomic message using thebatch() method. All operations within the batch are sent as one logical unit which succeed or fail together:
Subscribe to updates
Subscribe toLiveMap updates to receive realtime notifications when the map changes.
PathObject subscriptions observe a location and automatically track changes even if the LiveMap instance at that path is replaced. Instance subscriptions track a specific LiveMap instance, following it even if it moves in the channel object.
subscribeIterator() method for an async iterator syntax:
