2.0.1 • Published 2 years ago

@daun/pubsub v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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()

License

MIT License © Philipp Daun