Skip to content

Commit

Permalink
moar
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Sep 25, 2011
1 parent 65e4f42 commit 1821586
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/index.js
Expand Up @@ -24,6 +24,23 @@ EventEmitter.prototype.every = function every () {
return this;
};

/**
* Small utility to use a object to assign EventEmitters
*
* @param {Object} events
* @api public
*/

EventEmitter.prototype.multi = function (events) {
for (var event in events) {
if (events.hasOwnProperty(event)) {
this.on(event, events[event]);
}
}

return this;
};

/**
* Checks if the event is already added to the event emitter
*
Expand Down
29 changes: 29 additions & 0 deletions tests/eventreactor.test.js
Expand Up @@ -64,4 +64,33 @@ var EventEmitter = process.EventEmitter
count.should.equal(3);
}, 10);
}

, 'multiple event listeners': function () {
var EE = new EventEmitter
, count = 0;

function listen () {
count++;
}

EE.multi({
error: listen
, timeout: listen
, disconnect: listen
, reconnect: listen
, abort: listen
});

// test to see if all events applied
EE.emit('error');
EE.emit('timeout');
EE.emit('disconnect');
EE.emit('reconnect');
EE.emit('abort');

// see above for the odd timeout thingy
setTimeout(function () {
count.should.equal(5);
}, 10);
}
};

0 comments on commit 1821586

Please sign in to comment.