@daun/pubsub

2.0.1 • Public • Published

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

Package Sidebar

Install

npm i @daun/pubsub

Weekly Downloads

0

Version

2.0.1

License

MIT

Unpacked Size

19 kB

Total Files

12

Last publish

Collaborators

  • daun