tiny-pubsub is a super simple event management package written in javascript with no dependencies.
Right now tiny-pubsub is 827 bytes.
This is in no way mean't to replace rxjs. This is a small, synchronously operating, feature-light event driven programming library. RxJs is a full featured event driven programming library.
npm install --save tiny-pubsubThe api only has three functions. publish, subscribe, and unsubscribe.
event_definitions.js
// Using object singletons is a good way to register events.
const CHATROOM_JOIN = {};
export {CHATROOM_JOIN}app.js
import {subscribe, publish, unsubscribe} from 'tiny-pubsub'
import {CHATROOM_JOIN} from './event_definitions'
let logJoin = (name) => console.log(`${name} has joined the room!`);
subscribe(CHATROOM_JOIN, logJoin)
publish(CHATROOM_JOIN, "Luke")
// > Luke has joined the room!
unsubscribe(CHATROOM_JOIN, logJoin)
publish(CHATROOM_JOIN, "Luke")
// nothing will print
// alternatively you can use strings as event identifiers
subscribe("chatroom-join", logJoin)
publish("chatroom-join", "Luke")
// > Luke has joined the room!Send pull requests.
npm install --dev
npm run testMIT License.