zemitter
v0.2.5
Published
Advanced event emitter for node and the browser
Downloads
55
Maintainers
Readme
zemitter
Flexible Event Emitter for Node and the Browser
Install
$ npm install zemitter
Usage
var Emitter = require('zemitter')
var obj = {}
//either make an object become an event emitter
Emitter(obj) // returns obj
//or create a brand new emitter
var emitter = Emitter()
Example
emitter.on({
start: function(greeting, name){
console.log(greeting, name)
},
stop: function(){
},
scope: {}
})
emitter.on('start', function(){
})
emitter.on({
start: {
fn: function(){
},
scope: ''
},
stop: function(){}
})
emitter.emit('start', 'hello', 'world')
API
on
emitter.on({
'event_name': fn
})
emitter.on(['start','stop','exit'], fn)
emitter.on(['start','stop','exit'], [fn1, fn2])
off
emitter.off('start', fn)// remove fn as a listener to the 'start' event emitter.off('start') // remove all listeners to the start event emitter.off() // remove all listeners attached to this emitter
once
Attach a function that will only be called once, and then will be removed from the emitter
Tests
$ make
License
MIT