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 a number representation of the counter at this path. This is an alias for calling value().
If the path does not resolve to any specific instance, returns undefined.
Get a number representation of the counter at this path. This is an alias for calling value().
If the path does not resolve to any specific instance, returns undefined.
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.
Sends an operation to the Ably system to increment the value of a given LiveCounterInstance, or of the counter instance resolved from the path when using LiveCounterPathObject.
If called via LiveCounterInstance and the underlying instance at runtime is not a counter, or if called via LiveCounterPathObject 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.
Get the specific counter instance currently at this path.
If the path does not resolve to any specific instance, returns undefined.
The LiveCounterInstance at this path, or undefined if none exists.
Registers a listener that is called each time the object or a primitive value at this path is updated.
The provided listener receives a PathObject representing the path at which there was an object change, and, if applicable, an ObjectMessage that carried the operation that led to the change.
By default, subscriptions observe nested changes, but you can configure the observation depth
using the options parameter.
A PathObject subscription observes whichever value currently exists at this path. The subscription remains active even if the path temporarily does not resolve to any value (for example, if an entry is removed from a map). If the object instance at this path changes, the subscription automatically switches to observe the new instance and stops observing the old one.
An event listener function.
Optional options: PathObjectSubscriptionOptions
Optional subscription configuration.
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 the object or a primitive value at this path is updated.
This method functions in the same way as the regular PathObject.subscribe() method,
but instead returns an async iterator that can be used in a for await...of loop for convenience.
Optional options: PathObjectSubscriptionOptions
Optional subscription configuration.
An async iterator that yields PathObjectSubscriptionEvent objects.
Generated using TypeDoc
A PathObject representing a LiveCounter instance at a specific path.