1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-10 12:24:20 +01:00

wrote a very small custom event emitter

This commit is contained in:
Enrico Fasoli 2015-11-16 13:21:44 +01:00
parent 9344b360d7
commit 31ddef6338

25
lib/EventEmitter.js Normal file
View File

@ -0,0 +1,25 @@
// Custom event emitter for boards-api
var EventEmitter = function(){
this.listeners = {}
}
EventEmitter.prototype.on = function(name,handler){
if(this.listeners[name] === undefined)
this.listeners[name] = []
else if(handler && handler.apply && this.listeners[name].indexOf(handler) < 0)
this.listeners[name].push(handler)
}
EventEmitter.prototype.emit = function(name,arg){
var args = []
for(var a in arguments) if(a > 0) args.push(arguments[a])
if(this.listeners[name]){
for(var i in this.listeners[name]){
var listener = this.listeners[name][i]
if(listener && listener.apply) listener.apply(this,args)
}
}
}
module.exports = EventEmitter