- ...No external dependencies.
- ...Tests with tape.
- ...Decoupled publishing, i.e. non-blocking. Inspired by pubsub-js
- ...Small source, but not quite as tiny as tiny pubsub
npm i js-pub-n-sub
Uses ECMA features. Minimum node.js version: 6
- Declare const - Support
- Parameter defaulting - Support
- Arrow functions - Support
- Spread in array listerals - Support
Initialise a new channel
const pubSubChannel = require('js-pub-n-sub')();
Subscribe and publish
const subscriberFn = ({name}) => console.log(`Hello ${data}`);
const topic = 'greeting';
pubSubChannel.subscribe(topic, subscriberFn);
pubSubChannel.publish(topic, {name: 'World!'});
pubSubChannel.publish(topic, {name: 'Mars!'});
Pass the channel to consumers
require('ui-factory')(pubSubChannel);
require('model-factory')(pubSubChannel);