Interface LiveCounterInstance

LiveCounterInstance represents an Instance of a LiveCounter object.

Hierarchy

Properties

id: undefined | string

Get the object ID of the underlying instance.

If the underlying instance at runtime is not a LiveObject, returns undefined.

Methods

  • 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.

    Parameters

    Returns Promise<void>

    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 a number representation of the counter instance. This is an alias for calling value().

    If the underlying instance's value is not of the expected type at runtime, returns undefined.

    Returns undefined | number

  • Get a number representation of the counter instance. This is an alias for calling value().

    If the underlying instance's value is not of the expected type at runtime, returns undefined.

    Returns undefined | number

  • An alias for calling increment(-amount)

    Parameters

    • Optional amount: number

      The amount by which to decrease the counter value. If not provided, defaults to 1.

    Returns Promise<void>

    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 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.

    The operation is sent to Ably and, once accepted, applied locally. The returned promise resolves after the operation has been applied.

    Parameters

    • Optional amount: number

      The amount by which to increase the counter value. If not provided, defaults to 1.

    Returns Promise<void>

    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.

    Parameters

    Returns Subscription

    A Subscription object that allows the provided listener to be deregistered from future updates.

  • Get the current value of the counter instance. If the underlying instance at runtime is not a counter, returns undefined.

    Returns undefined | number

Generated using TypeDoc