Protected
constructorInternal
Should not be instantiated be the user directly.
Internal
internalSubscribe to an event.
The event to listen for.
The callback to invoke when the event is emitted.
A function to unsubscribe the listener.
Subscribe to an event once.
The listener will be automatically unsubscribed after the first time it is called.
Note that the listener will be unsubscribed BEFORE the actual listener callback is invoked.
The event to listen for.
The callback to invoke when the event is emitted.
A function to prematurely unsubscribe the listener.
Overview
A lightweight event system that allows hierarchical event propagation (similar to DOM event bubbling).
Events triggered on a child (e.g., a
Collection
) will propagate up to its parent (e.g., the parentDb
and its parentDataAPIClient
), unless explicitly stopped.This allows to quickly (and granular-ly) enable listen for events at any level of the hierarchy, and stop propagation at any level if needed.
Event Hierarchy
Events follow a structured hierarchy:
Collection | Table
→Db
→Client
AstraAdmin | DbAdmin
→Client
If, for instance, you have two different
Collection
objects which both point to the same collection, only the one that triggered the event will be notified.Example
On errors in listeners
If an error is thrown in a listener, it will be silently ignored and will not stop the propagation of the event.
If you need to handle errors in listeners, you must wrap the listener in a try/catch block yourself.
Remarks
Having a custom implementation avoids a dependency on
events
for maximum compatibility across environments & module systems.See
DataAPIClientEventMap