Protected
constructorInternal
Should not be instantiated be the user directly.
Private
Readonly
Internal
#listenersPrivate
Readonly
Internal
#parentEmit an event.
Should probably never be used by the user directly.
Note: Errors thrown by any listeners will be silently ignored. It will not stop the propagation of the event.
true
if the event had listeners, false
otherwise.
Subscribe 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