
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
event-emitter-es6
Advanced tools
A small event emitter library. Works in the browser and in Node. Can be used with es6 inheritance or as stand-alone lib.
Inspired by the tiny-emitter package on npm.
For more information you can see jsdoc info in index.es6
file.
Very simply applies to express.
Node
npm install event-emitter-es6 --save
Browser
bower install event-emitter-es6 --save
<script src="bower_components/event-emitter-es6/dist/event-emitter.min.js"></script>
or apply via express
var express = require('express');
var app = express();
<... your code here ...>
app.use( require('event-emitter-es6/router') );
<script src="event-emitter-es6/event-emitter.min.js"></script>
Node
var EventEmitter = require('event-emitter-es6');
var emitter = new Emitter();
emitter.on('some-event', function listener1 (param1, param2, param3) {
console.info('listener1', param1, param2, param3);
});
emitter.on('some-event', function listener2 (param1, param2, param3) {
console.info('listener2', param1, param2, param3);
});
emitter.emit('some-event', 'some-val1', 'some-val2', 'some-val3');
Browser
var emitter = new EventEmitter();
emitter.on('some-event', function listener1 (param1, param2, param3) {
console.info('listener1', param1, param2, param3);
});
emitter.on('some-event', function listener2 (param1, param2, param3) {
console.info('listener2', param1, param2, param3);
});
emitter.emit('some-event', 'some-val1', 'some-val2', 'some-val3');
ES6
class SomeEmittingClass extends EventEmitter {
constructor() {
super();
}
fireExampleEvent() {
this.emit('some-event', 'some-val1', 'some-val2', 'some-val3');
}
}
var emittingInstance = new SomeEmittingClass();
emittingInstance.on('some-event', function listener1 (param1, param2, param3) {
console.info('listener1', param1, param2, param3);
});
emittingInstance.on('some-event', function listener2 (param1, param2, param3) {
console.info('listener2', param1, param2, param3);
});
emittingInstance.fireExampleEvent();
An option can be passed to constructor
opts
- settings object for create event emitteropts.emitDelay
- delay in ms to emit event. If passed 0 - all events emits synchronously. By default = 10opts.strictMode
- when emit event with no listeners - fires error. By default = falseCompletely destroys event emitter.
Subscribe to an event
event
- the name of the event to subscribe tocallback
- the function to call when event is emitted (for transfer context use bind method of Function.prototype)Subscribe to an event only once
event
- the name of the event to subscribe tocallback
- the function to call when event is emitted (for transfer context use bind method of Function.prototype)Unsubscribe from an event or all events. If no callback is provided, it unsubscribes you from all events.
event
- the name of the event to unsubscribe fromcallback
- the function used when binding to the event. If you used function with bind method - must be passed the same function, that was getted after binding.Trigger a named event
event
- the event name to emitarguments...
- any number of arguments to pass to the event subscribersTrigger a named event immediate (even the emitter was created as async instance)
event
- the event name to emitarguments...
- any number of arguments to pass to the event subscribersBuild (Browserifies, and minifies)
npm install
npm run build
Test
npm install
npm run test
FAQs
Small event emitter for using in es6 and plain js
The npm package event-emitter-es6 receives a total of 4,100 weekly downloads. As such, event-emitter-es6 popularity was classified as popular.
We found that event-emitter-es6 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.