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. Instead, the objects will be updated when the batched operations are applied by the Ably service and echoed back to the client.
A synchronous function that receives a BatchContext used to group operations together.
A promise which resolves upon success of the batch operation and rejects with an ErrorInfo object upon its failure.
Get an in-memory JavaScript object representation of the object instance. For primitive types, this is an alias for calling value().
When compacting a LiveMap, 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 object instance. Binary values are converted to base64-encoded strings.
When compacting a LiveMap, 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.
An alias for calling increment(-amount)
Optional amount: number
The amount by which to decrease the counter value. If not provided, defaults to 1.
A promise which resolves upon success of the operation and rejects with an ErrorInfo object upon its failure.
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.
Navigate to a child entry within the collection by obtaining the Instance at that entry. The entry in a collection is identified with a string key.
Returns undefined if:
The key to get the child entry for.
An Instance representing either a LiveObject or a primitive value (string, number, boolean, JSON-serializable object or array, or binary data), or undefined if the underlying instance at runtime is not a collection object, the key does not exist, the referenced LiveObject has been deleted, or this collection object itself has been deleted.
Sends an operation to the Ably system to increment the value of the underlying counter when using AnyInstance, or of the counter instance resolved from the path when using AnyPathObject.
If called via AnyInstance and the underlying instance at runtime is not a counter, or if called via AnyPathObject and the counter instance at the specified path cannot be resolved at the time of the call, this method throws an error.
This does not modify the underlying data of the counter. Instead, the change is applied when the published operation is echoed back to the client and applied to the object. To get notified when object gets updated, use PathObject.subscribe or Instance.subscribe, as appropriate.
Optional amount: number
The amount by which to increase the counter value. If not provided, defaults to 1.
A promise which resolves upon success of the operation and rejects with an ErrorInfo object upon its failure.
Returns an iterable of keys in the map.
If the underlying instance at runtime is not a map, returns an empty iterator.
Sends an operation to the Ably system to remove a key from the underlying map when using AnyInstance, or from the map instance resolved from the path when using AnyPathObject.
If called via AnyInstance and the underlying instance at runtime is not a map, or if called via AnyPathObject and the map instance at the specified path cannot be resolved at the time of the call, this method throws an error.
This does not modify the underlying data of the map. Instead, the change is applied when the published operation is echoed back to the client and applied to the object. To get notified when object gets updated, use PathObject.subscribe or Instance.subscribe, as appropriate.
The key to remove.
A promise which resolves upon success of the operation and rejects with an ErrorInfo object upon its failure.
Sends an operation to the Ably system to set a key to a specified value on the underlying map when using AnyInstance, or on the map instance resolved from the path when using AnyPathObject.
If called via AnyInstance and the underlying instance at runtime is not a map, or if called via AnyPathObject and the map instance at the specified path cannot be resolved at the time of the call, this method throws an error.
This does not modify the underlying data of the map. Instead, the change is applied when the published operation is echoed back to the client and applied to the object. To get notified when object gets updated, use PathObject.subscribe or Instance.subscribe, as appropriate.
The key to set the value for.
The value to assign to the key.
A promise which resolves upon success of the operation and rejects with an ErrorInfo object upon its 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.
Get the current value of the underlying counter or primitive.
If the underlying value is a primitive, this reflects the value at the corresponding key in the collection at the time this instance was obtained.
If the underlying instance at runtime is neither a counter nor a primitive value, returns undefined.
Returns an iterable of values in the map. Each value is represented as a Instance.
If the underlying instance at runtime is not a map, returns an empty iterator.
Generated using TypeDoc
Represents an Instance when its underlying type is not known. Provides a unified interface that includes all possible methods.
Each method supports type parameters to specify the expected underlying type when needed.