It's a very tiny library for publish/subscribe(pubsub) operations. There's no dependency. It's only 933(gziped: 437) byte. Written in TypeScript
100% coverage.
# NPM
npm install tiny-tiny-pubsub
# Yarn
yarn add tiny-tiny-pubsub
import pubsub from 'tiny-tiny-pubsub';
pubsub.on('test', (data) => {
console.log('called with ' + data);
});
import pubsub from 'tiny-tiny-pubsub';
pubsub.off('test', fn);
import pubsub from 'tiny-tiny-pubsub';
pubsub.trigger('test', 'sample data');
It clears all event listeners.
import pubsub from 'tiny-tiny-pubsub';
pubsub.clear();
Pubsub be able to support wildcard text matching.
For example:
If there are event registrations as below and user calls it with trigger
method.
pubsub.on("john", () => console.log("john");
pubsub.on("john.doe", () => console.log("john's name");
pubsub.on("john.doe.mail", () => console.log("john's mail");
pubsub.trigger("john.*")
all previously defined functions must be called except "john".
// console output
"john's name";
"john's mail";
or user should be able to remove event listeners based on wildcards.
pubsub.off('john.*');
pubsub.trigger('john');
pubsub.trigger('john.doe');
pubsub.trigger('john.doe.mail');
// console output
'john';
there must be only one listener in listeners array that is "john" Because user removed all listeners which matched with wildcard query that ends with asterix except "john".
MIT