Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ncuillery/single-events-eventemitter
Simple instance of the Node.js EventEmitter, available as singleton through your whole app.
https://github.com/ncuillery/single-events-eventemitter
Last synced: 1 day ago
JSON representation
Simple instance of the Node.js EventEmitter, available as singleton through your whole app.
- Host: GitHub
- URL: https://github.com/ncuillery/single-events-eventemitter
- Owner: ncuillery
- Created: 2015-03-13T09:36:37.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-13T12:54:37.000Z (almost 10 years ago)
- Last Synced: 2024-11-22T14:07:22.103Z (2 months ago)
- Language: JavaScript
- Size: 113 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# single-events-eventemitter
[![Build Status](https://travis-ci.org/ncuillery/single-events-eventemitter.png)](https://travis-ci.org/ncuillery/single-events-eventemitter)When you have to use the [Node.js event API](https://nodejs.org/api/events.html), you have to
create an instance of `EventEmitter`. If a module B has to listen event emitted from module A, you
can simply require A in B and do something like this:
```javascript
moduleA.on('notification', function () {
// Do something
});
```But if you need an single instance shared by multiple emitters and listeners (kind of an event bus)
then you need to wrap your instance in a module like this:
```javascript
var EventEmitter = require('events').EventEmitter;
var eventEmitter = new EventEmitter();
module.exports = eventEmitter;
```These 3 lines of code are exactly what this package will spare you and it's its sole purpose :wink: