oja-pubsub

This module is a subset of eBay Oja framework.
The module defines generic actions that can be used to organize actions into publishers and subscribers that are completely disconnected from each others.
Installation
$ npm install @ebay/oja-pubsub --save
Actions
- action('oja/subscribe', 'topic', listener) - subscribe to the event
- action('oja/unsubscribe', 'topic', listener) - unsubscribe from the event
- action(oja/dispatch, 'topic', eventData) - dispatch event to the subscribers
Listener
function (eventType, ...eventData) {}
Usage
- Subscribing to the event:
const { createContext } = require('@ebay/oja-action');
const context = await createContext();
const listener = await context.action('oja/subscribe', 'topic', (eventType, eventData) => {
console.log(eventData);
});
await context.action('oja/dispatch', 'topic', eventData);
- Unsubscribing from the event:
await context.action('oja/unsubscribe', 'topic', listener);
Subscribing as part of other action
context => {
const listener = context.action(
'oja/subscribe', 'topic', (eventType, eventData) => {
console.log(eventData);
}
);
}
To trigger subscription, one needs to trigger the respective action.