Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jetradar/dispatcher
extremely simple blazing-fast pure javascript publisher-subscriber
https://github.com/jetradar/dispatcher
Last synced: about 1 month ago
JSON representation
extremely simple blazing-fast pure javascript publisher-subscriber
- Host: GitHub
- URL: https://github.com/jetradar/dispatcher
- Owner: jetradar
- Created: 2016-01-21T08:27:02.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-21T11:34:14.000Z (almost 9 years ago)
- Last Synced: 2024-10-08T14:56:18.892Z (2 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-blazingly-fast - dispatcher - extremely simple blazing-fast pure javascript publisher-subscriber (JavaScript)
README
# dispatcher
extremely simple blazing-fast pure javascript publisher-subscriber## Installation
`npm install @jetradar/dispatcher --save`## Examples
```javascript
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