Skip to content

Commit

Permalink
Adds special event to EventEmitter that fired when any other event is…
Browse files Browse the repository at this point in the history
… fired
  • Loading branch information
mairatma committed May 29, 2015
1 parent 8772bbb commit 48ced54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/events/EventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class EventEmitter extends Disposable {
listened = true;
}

if (event !== '*') {
this.emit.apply(this, ['*', event].concat(args));
}

return listened;
}

Expand Down
9 changes: 9 additions & 0 deletions test/src/events/EventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ describe('EventEmitter Tests', function() {
assert.strictEqual(0, listener.callCount);
});

it('should emit special "*" event for all other events that are emitted', function() {
var listener = sinon.stub();

this.emitter.on('*', listener);
this.emitter.emit('event', 1, 2);
assert.strictEqual(1, listener.callCount);
assert.deepEqual(['event', 1, 2], listener.args[0]);
});

it('should run listeners in the order they were added', function() {
var order = '';
var listener1 = function() {
Expand Down

0 comments on commit 48ced54

Please sign in to comment.