A simple publish/subscribe implementation for node and the browser.
npm i @harryhope/messenger
import messenger from '@harryhope/messenger'
messenger.on('myEvent', name =>
console.log(`Hello there, ${name}`)
)
messenger.send('myEvent', 'Elvis')
Subscribe to an event/topic with a callback function.
const myCallback = str => console.log(`Hello ${str}`)
messenger.on('hello', myCallback)
Unsubscribe to an event.
messenger.off('hello', myCallback)
Broadcast a message to all subscribers of an event.
messenger.send('hello', 'world')
// Displays 'Hello world' in the console.
To build the src just run npm run build
.
Tests can be run with npm test
.