voltrevo-event-emitter
v1.1.2
Published
My utopian vision for simple eventing.
Downloads
3
Readme
voltrevo-event-emitter
My utopian vision for simple eventing.
An event emitter that probably does everything you actually need in only 70 lines of code.
Install
$ npm install --save voltrevo-event-emitter
Usage
'use strict';
var EventEmitter = require('voltrevo-event-emitter');
var ee = EventEmitter();
// events are asynchronous
ee.emit('foo', 'bar');
ee.on('foo', function(value) {
console.log(value); // bar
});
// .once works as usual
ee.emit('boom');
ee.emit('boom');
ee.once('boom', function() {
console.log('boom'); // only one boom
});
// .on and .once return Collection handles, which have .remove
ee.emit('unicorn');
var listener = ee.on('unicorn', function() {
console.log('A wild unicorn appeared!'); // this never happens
});
listener.remove();
License
MIT © Andrew Morris