Data Provider includes an event emitter that allows to be continually informed about what is happening and react in consequence.
Normally, using the events API directly should not be necessary, as Data Provider addons usually make this job for you and provide all needed reactivity, but there are some cases in which can be useful.
Their APIS are described in the providers and selectors methods API page, and their names should be descriptive enough to fully understand the purpose of each one, but, anyway:
- Methods prefixed with
onceautomatically unsubscribe the provided listener after its first execution.
- Methods suffixed with
Childsubscribe the listener to events happening on any children (queried instances) of the provider or selector.
As all mentioned methods require same arguments to be executed, we will use the
on method as example in the API description:
eventName(String): Event name to subscribe to. Read events names chapter in this page for further info.
listener(Function): The callback to be invoked when the specific
In this chapter are described the
eventNamescommon to all providers. Addons can emit its own
eventNames, which should be described in its own documentation.
Available event names are:
readStart: Dispatched when the
readmethod has not cache and internally calls to the addon
readMethod. When the provider or selector result is cached, this event is not dispatched.
readSuccess: Dispatched when the
readmethod is resolved successfully. When the provider or selector result is cached, this event is not dispatched.
readError: Dispatched when the
readmethod is rejected with an error.
cleanCache: Dispatched when the
cleanCachemethod is executed.
init: Dispatched when a new provider or selector instance is created.
resetState: Dispatched when the
resetStatemethod is executed.
You can also use next wildcard to listen to any of the events described before:
*: Dispatched when any of the previously described event names are dispatched.
When using wildcards, the original
eventNamewill be received as first argument in the
All described event names are exported as constants in order to facilitate their usage. They are available at the
eventNames property at top-level export of the library. The map of equivalences is:
listener function should follow the next API:
eventName(String): When the listener was subscribed using the
*wildcard, it will receive the
eventNamecausing the execution as first argument.
child(provider or selector) : When the listener was subscribed using a child method (
onceChild) it will receive the child causing the execution as first argument, or in second argument in case the listener was subscribed using the