This Event Emitter module allows one or more functions to be attached to named events and those named events to be emitted.
Check out the Code Review for feedback by community members.
This was originally created in 2018.
First, clone the repository:
$ git clone https://github.com/aelliott1485/emitter.git
Then go into the local directory for the repository:
$ cd emitter
Next install the dependencies (e.g. test frameworks)
$ npm install
Then the tests can be run to ensure it works as expected:
$ npm test
var emitter = new EventEmitter();
//register the handler function (defined below)
emitter.on('sent', receive);
//later, emit the event and pass data, which will be sent to the handler function(s)
emitter.emit('sent', {"foo": "bar"});
function receive(data) {
//handle data
}
Emits a named event with any number of arguments.
eventName
<string>
the name of the eventcallback
<Function>
Registers a handler function to be called whenever the named event is emitted.
eventName
<string>
the name of the eventcallback
<Function>
Registers a handler function to only be called the first time the named event is emitted.
eventName
<string>
the name of the eventcallback
<Function>
Removes a specific previously-registered event handler and/or all previously-registered event handlers.