eventemitter3
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
EventEmitter3 is a high-performance EventEmitter for both Node.js and browser environments. As the name suggests, it provides an event-driven architecture where certain kind of events can trigger certain actions. It's designed with an emphasis on performance and operational speed, while also maintaining compatibility with the Node.js and browser interfaces. Some key differences that set EventEmitter3 apart include the removal of domain support and the absence of throwing an error when emitting an 'error' event, if no one is listening.
To use EventEmitter3, the first step is to install the package through npm using the command npm install --save eventemitter3
. After installing the package successfully, you can start using it by requiring the module in your JavaScript code as follows:
var EventEmitter = require('eventemitter3');
After this, you can create your own EventEmitter instances and start using the module in your application. Here's an example on how you can utilize the EventEmitter object, once initialized:
var EE = new EventEmitter()
, context = { foo: 'bar' };
function emitted() {
console.log(this === context); // true
}
EE.once('event-name', emitted, context);
EE.on('another-event', emitted, context);
EE.removeListener('another-event', emitted, context);
The above code creates a new EventEmitter instance and sets up an event listener that triggers when an event called 'event-name' is emitted. A contextual 'this' value is set for the emitted events which can modify the context of functions, negating the need for using fn.bind
.
For extensive documentation and API details of EventEmitter3, it is recommended to follow the official Node.js documentation at http://nodejs.org/api/events.html. The GitHub repository for EventEmitter3, found at git://github.com/primus/eventemitter3.git, can also be a valuable resource for additional information and clarification.