Readonly id
Get the object ID of the underlying instance.
If the underlying instance at runtime is not a LiveObject, returns undefined.
Batch multiple operations together using a batch context, which wraps the underlying PathObject or Instance from which the batch was called. The batch context always contains a resolved instance, even when called from a PathObject. If an instance cannot be resolved from the referenced path, or if the instance is not a LiveObject, this method throws an error.
Batching enables you to group multiple operations together and send them to the Ably service in a single channel message. As a result, other clients will receive the changes in a single channel message once the batch function has completed.
The objects' data is not modified inside the batch function. The batched operations are sent to Ably and, once accepted, applied locally. The returned promise resolves after all operations have been applied.
A synchronous function that receives a BatchContext used to group operations together.
A promise which resolves after all batched operations have been accepted by Ably and applied locally, or rejects with an ErrorInfo object upon failure.
Get an in-memory JavaScript object representation of the map instance.
Cyclic references are handled through memoization, returning shared compacted
object references for previously visited objects. This means the value returned
from compact() cannot be directly JSON-stringified if the object may contain cycles.
If the underlying instance's value is not of the expected type at runtime, returns undefined.
Use compactJson() for a JSON-serializable representation.
Get a JSON-serializable representation of the map instance.
Binary values are converted to base64-encoded strings.
Cyclic references are represented as { objectId: string } instead of in-memory pointers,
making the result safe to pass to JSON.stringify().
If the underlying instance's value is not of the expected type at runtime, returns undefined.
Use compact() for an in-memory representation.
Returns an iterable of key-value pairs for each entry in the map. Each value is represented as an Instance corresponding to its key.
If the underlying instance at runtime is not a map, returns an empty iterator.
Returns the value associated with a given key as an Instance.
If the associated value is a primitive, returns a PrimitiveInstance that serves as a snapshot of the primitive value and does not reflect subsequent changes to the value at that key.
Returns undefined if the key doesn't exist in the map, if the referenced LiveObject has been deleted,
or if this map object itself has been deleted.
The key to retrieve the value for.
An Instance representing a LiveObject, a primitive type (string, number, boolean, JSON-serializable object or array, or binary data) or undefined if the key doesn't exist in a map or the referenced LiveObject has been deleted. Always undefined if this map object is deleted.
Sends an operation to the Ably system to remove a key from a given LiveMapInstance, or from the map instance resolved from the path when using LiveMapPathObject.
If called via LiveMapInstance and the underlying instance at runtime is not a map, or if called via LiveMapPathObject and the map instance at the specified path cannot be resolved at the time of the call, this method throws an error.
The operation is sent to Ably and, once accepted, applied locally. The returned promise resolves after the operation has been applied.
The key to remove.
A promise which resolves after the operation has been accepted by Ably and applied locally, or rejects with an ErrorInfo object upon failure.
Sends an operation to the Ably system to set a key to a specified value on a given LiveMapInstance, or on the map instance resolved from the path when using LiveMapPathObject.
If called via LiveMapInstance and the underlying instance at runtime is not a map, or if called via LiveMapPathObject and the map instance at the specified path cannot be resolved at the time of the call, this method throws an error.
The operation is sent to Ably and, once accepted, applied locally. The returned promise resolves after the operation has been applied.
The key to set the value for.
The value to assign to the key.
A promise which resolves after the operation has been accepted by Ably and applied locally, or rejects with an ErrorInfo object upon failure.
Registers a listener that is called each time this instance is updated.
If the underlying instance at runtime is not a LiveObject, this method throws an error.
The provided listener receives an Instance representing the updated object, and, if applicable, an ObjectMessage that carried the operation that led to the change.
Instance subscriptions track a specific object instance regardless of its location. The subscription follows the instance if it is moved within the broader structure (for example, between map entries).
If the instance is deleted from the channel object entirely (i.e., tombstoned), the listener is called with the corresponding delete operation before automatically deregistering.
An event listener function.
A Subscription object that allows the provided listener to be deregistered from future updates.
Registers a subscription listener and returns an async iterator that yields subscription events each time this instance is updated.
This method functions in the same way as the regular Instance.subscribe() method,
but instead returns an async iterator that can be used in a for await...of loop for convenience.
An async iterator that yields InstanceSubscriptionEvent objects.
Generated using TypeDoc
LiveMapInstance represents an Instance of a LiveMap object. The type parameter T describes the expected structure of the map's entries.