subnpub

1.1.8 • Public • Published

subnpub

CircleCI

Minimal implementation of publish/subscribe pattern

USAGE

const SubNPub = require("subnpub");
const snp = SubNPub();
 
const fn1 = str => `1-Called Me with: ${str}`;
const fn2 = str => `2-Called Me with: ${str}`;
const fn3 = str => `3-Called Me with: ${str}`;
 
// subscribe enforces uniqueness
snp.subscribe(fn1);
// or:
snp.subscribe(fn1, fn2, fn3);
// or:
snp.subscribe([fn1, fn2, fn3]);
 
 
snp.publish("test"); // dispatches argument to all subscribers
 
snp.has(fn1); // true
 
snp.length(); // 3
 
 
snp.unsubscribe(fn1); // removes subscriber
// or:
snp.unsubscribe(fn1, fn2, fn3);
// or:
snp.unsubscribe([fn1, fn2, fn3]);
 
snp.reset(); // removes all subscribers

Package Sidebar

Install

npm i subnpub

Weekly Downloads

2

Version

1.1.8

License

ISC

Unpacked Size

7.58 kB

Total Files

7

Last publish

Collaborators

  • stormcrows