@daun/pubsub
v2.0.1
Published
Simple event bus / pubsub broker
Downloads
5
Readme
Pub-Sub
Simple DOM-based event bus / pubsub broker.
Usage
import pubsub from '@daun/pubsub'
Publish events
The second argument will be passed to each event handler.
pubsub.publish('page:visit', { url: window.location })
Subscribe to events
pubsub.subscribe('page:visit', ({ detail }) => {
console.log(detail.url)
})
Unsubscribe from events
The subscribe
method returns a function that can be used to unsubscribe.
const unsubscribe = pubsub.subscribe('page:visit', () => { /* */ })
unsubscribe()