Skip to content

Latest commit

 

History

History
37 lines (25 loc) · 804 Bytes

README.md

File metadata and controls

37 lines (25 loc) · 804 Bytes

dispatcher

extremely simple blazing-fast pure javascript publisher-subscriber

Installation

npm install @jetradar/dispatcher --save

Examples

import dispatcher from '@jetradar/dispatcher';

dispatcher.on('beer', (eventName, data) => {
  console.log(data.isDraught);

}

dispatcher.send('beer', {
  isDraught: true
});

dispatcher.trigger('beer', {
  isDraught: false
});

// true
// false

API Reference

dispatcher.on(eventName, handler) — subscribes handler to eventName

dispatcher.trigger(eventName, payload) or dispatcher.send(eventName, payload) — Fires eventName event to all

dispatcher.all(handler) or dispatcher.on('*', handler) — subscribes for all the events being fired

dispatcher.off(eventName) — removes eventName from events list