@dharmax/pubsub
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

General

This is a pub-sub dispatcher that has a few additional tweaks. It works with topics and verbs, and the verb can be a wildcard (in the listener, of course) and it keeps the origin of the event, as well as a trace feature - which can both be useful to track intricate event flows.

installation

npm i @dharmax/pubsub

Usage

import dispatcher from '@dharmax/pubsub'


dispatcher.trigger('tester', 'my-topic:my-verb', {myString: 'my data'})

dispatcher.trace( true)

const myListener = dispatcher.on('my-topic:my-verb', event => {
    console.log({
        data: event.data.myString,
        origin: event.origin
    })
})

// you can destroy the handler
dispatcher.off(myListener)

You also have the method once and dispatcher.triggerAsync .

Package Sidebar

Install

npm i @dharmax/pubsub

Weekly Downloads

2

Version

1.1.0

License

ISC

Unpacked Size

16.4 kB

Total Files

11

Last publish

Collaborators

  • dharmax