@marianmeres/pubsub
v1.2.5
Published
Basic publish-subscribe.
Downloads
35
Readme
@marianmeres/pubsub
Basic publish-subscribe.
Install
$ npm i @marianmeres/pubsub
Usage
import { createPubSub } from '@marianmeres/pubsub;
const { publish, subscribe, subscribeOnce, unsubscribe, unsubscribeAll } = createPubSub();
// create subscription (returns unsub function)
const unsub = subscribe('foo', console.log);
// publish
publish('foo', 'bar'); // logs 'bar'
// unsubscribe
unsub();
// or more general alternatives to above
unsubscribe('foo', console.log);
unsubscribeAll('foo');
// now this is a no-op as no subscription exists
publish('foo', 'baz');