0.0.4 • Published 10 years ago
smart-emitter v0.0.4
Install
Install with npm
$ npm install smart-emitterOr download from github
Usage
Create Instance
smart-emitter is using Factory design pattern, so you cant use new method.
For creating new instance use createInstance function.
var SE = require('smart-emitter');
var emitter = SE.createInstance();Add Listenre if not exists
emitter.addListenerIfNotExists('event', ( ) => {
console.log('ok');
})On
Just adds one more listener
emitter.on('event', ( ) => {
console.log('ok');
})Add Unique Listener
This method removes all listeners on this channel and adds new.
emitter.addUniqueListener('event', ( ) => {
console.log('ok');
})Emit
emitter.emit('event');Remove Listener
Removes listener subscribed on given event
emitter.removeListener('event', function);Remove All Listeners
Removes all listeners subscribed on given event
emitter.removeAllListeners('event', function);Listeners Count
Returns listeners count subscribed on given event
emitter.listenerCount('event');