UXL Event Aggregator
Build Status | Statements | Branches | Functions | Lines |
---|
| | | | |
Installation
npm i @uxland/event-aggregator
Usage
Event publish
To publish an event you must specify an eventId and an optional payload that will be collected by subscriber.
const payload = { foo: 'bar' };
publish('EVENT-ID', payload);
Event subscription
In order to subscribe to an event you must specify an eventId and a callback function that will be called when that event is received.
const callback = (payload: any): void => {};
subscribe('EVENT-ID', callback);
Event subscription (only once)
In order to subscribe to an event, only once, you must specify an eventId and a callback function that will be called when that event is received. For the next publishes of that event, this subscriber will not receive that event.
const callback = (payload: any): void => {};
subscribeOnce('EVENT-ID', callback);