Interface: Watcher

ReactiveDb.Watcher

Represents a subscription to a set of documents within a collection.
This object monitors the subscription and receives (realtime) notifications when some subscribed documents change.

Monitoring is done throw the Promise API:

  • a Watcher is successfully completed when the client regularly cancels the subscription (using the unwatch method, in this case the then callback is invoked).
  • it is failed when the back end revokes the subscription (in this case, an error is emitted to the catch callback).

Received notifications simply invoke the forEach callback.

Instances of this interface are built using the ReactiveDb#watchOne and ReactiveDb#watchMany functions.

Extends

Members

(readonly) options :ReactiveDb.WatchOptions

Retrieves the options associated with the subscription managed by this instance.

Type:
  • ReactiveDb.WatchOptions

Methods

forEach(callback) → {Promise.<void>|ReactiveDb.Unwatcher}

Registers a callback function to receive notifications related to the subscription managed by this instance.

If the subscription receives notifications before registering the callback, they are not lost and will be sent to the callback as soon as it will be registered.

Only one callback may be registered at a time on a ReactiveDb.Watcher object. Registering another callback overwrites the previous one if any.

Parameters:
Name Type Description
callback function

The callback function invoked each time a notification is sent by the back end to the subscription managed by this instance.
The function is simply called with an instance of ReactiveDb.QueryNotification.

Returns:

The Watcher instance is returned with a limited API exposure, so that only Promise's then and catch methods can be chained, as well as the ReactiveDb.Unwatcher#unwatch method.

Type
Promise.<void> | ReactiveDb.Unwatcher

unwatch()

Cancels the subscription managed by this instance.

It will end in calling the Promise#then callback of the ReactiveDb.Watcher object it is attached to.

Inherited From:
deprecated
Authentication
ServerlessDb
ReactiveDb