Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nsisodiya/eventbus
Simple event bus for Node.js
https://github.com/nsisodiya/eventbus
Last synced: about 1 month ago
JSON representation
Simple event bus for Node.js
- Host: GitHub
- URL: https://github.com/nsisodiya/eventbus
- Owner: nsisodiya
- License: mit
- Created: 2016-03-11T06:17:36.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-11T07:03:18.000Z (almost 9 years ago)
- Last Synced: 2024-08-10T06:10:37.195Z (5 months ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @nsisodiya/eventbus
Simple EventBus for Node.js# Installation
```
npm install --save @nsisodiya/eventbus
```# Usage
```js
import EventBus from '@nsisodiya/eventbus';var b1 = new EventBus();
var unsub1 = b1.subscribe("ADD_EVENT", function (obj) {
console.log("AddEvent Received at Section 1", obj);
});var unsub2 = b1.subscribe("ADD_EVENT", function (obj) {
console.log("AddEvent Received at Section 2", obj);
});var unsub3 = b1.subscribeAll(function (obj, obj2) {
console.log("Some Event Received at Section 3", obj, obj2);
});b1.publish("ADD_EVENT", {done: false, title: "write JS"});
/*
AddEvent Received at Section 1 Object {done: false, title: "write JS"}
AddEvent Received at Section 2 Object {done: false, title: "write JS"}
Some Event Received at Section 3 ADD_EVENT Object {done: false, title: "write JS"}
*/b1.publish("EDIT_EVENT", {done: false, title: "write JS"});
/*
Some Event Received at Section 3 EDIT_EVENT Object {done: false, title: "write JS"}
*/unsub1();
b1.publish("ADD_EVENT", {done: false, title: "write JS"});
/*
AddEvent Received at Section 2 Object {done: false, title: "write JS"}
Some Event Received at Section 3 ADD_EVENT Object {done: false, title: "write JS"}
*/unsub3();
b1.publish("EDIT_EVENT", {done: false, title: "write JS"});
/*
No Output and no one subscribe this event.
*/
```