tiny-events
v1.0.1
Published
A very tiny EventEmitter implementation for client- and server-side code.
Downloads
6,623
Maintainers
Readme
tiny-events
A very tiny (400b) EventEmitter implementation for client- and server-side code.
installation
npm install --save tiny-events
usage
instantiate the object directly..
// import the module
var EventEmitter = require('tiny-events').EventEmitter;
// instantiate the object
var events = new EventEmitter();
// listen to 'foo' events
events.on('foo', function (data) {
console.log('foo occured!');
});
// emit a 'foo' event
events.emit('foo');
// emit a 'foo' event with some data
events.emit('foo', 'hello world');
// remove all foo event listeners
events.off('foo');
... or subclass it.
var utils = require('utils');
var EventEmitter = require('tiny-events').EventEmitter;
function MyClass() {
EventEmitter.call(this);
}
util.inherits(MyClass, EventEmitter);
API
on(type: string, listener: Function): EventEmitter
once(type: string, listener: Function): EventEmitter
off(type: string, listener?: Function): EventEmitter
emit(type: string, ...args: any[]): EventEmitter