@marianmeres/pubsub
TypeScript icon, indicating that this package has built-in type declarations

1.2.5 • Public • Published

@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');

Readme

Keywords

Package Sidebar

Install

npm i @marianmeres/pubsub

Weekly Downloads

2

Version

1.2.5

License

MIT

Unpacked Size

7.25 kB

Total Files

7

Last publish

Collaborators

  • marianmeres