event-emitter-es6
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.
Install
Node
npm install event-emitter-es6 --save
Browser
bower install event-emitter-es6 --save
or apply via express
var express = ;var app = ; <... your code here ...> app;
Usage
Node
var EventEmitter = ;var emitter = ; emitter;emitter;emitter;
Browser
var emitter = ; emitter; emitter; emitter;
ES6
{ super; } { this; } var emittingInstance = ; emittingInstance;emittingInstance;emittingInstance;
Instance Methods
constructor([opts])
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 = false
destroy()
Completely destroys event emitter.
on(event, callback)
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)
once(event, callback)
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)
off(event[, callback])
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.
emit(event[, ...arguments])
Trigger a named event
event
- the event name to emitarguments...
- any number of arguments to pass to the event subscribers
emitSync(event[, ...arguments])
Trigger 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 subscribers
Build
Build (Browserifies, and minifies)
npm install
npm run build
Test
Test
npm install
npm run test
Change list
Version 1.1.5
- destroy() method of class
Version 1.1.4
- All code covered with tests