Skip to content

Commit

Permalink
Added Emitter#has(event)
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed May 10, 2012
1 parent 872de89 commit 05d95f0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ $ npm install emitter-component
### Emitter#emit(event, ...)

Emit an `event` with variable option args.

### Emitter#has(event)

Check if this emitter has `event` handlers.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,9 @@ Emitter.prototype.emit = function(event){

return this;
};

Emitter.prototype.has = function(event){
var fns = this.callbacks[event];
return !!(fns && fns.length);
};

17 changes: 17 additions & 0 deletions test/emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,21 @@ describe('Emitter', function(){
calls.should.eql([]);
})
})

describe('.has(event)', function(){
describe('when handlers are present', function(){
it('should return true', function(){
var emitter = new Emitter;
emitter.on('foo', function(){});
emitter.has('foo').should.be.true;
})
})

describe('when no handlers are present', function(){
it('should return false', function(){
var emitter = new Emitter;
emitter.has('foo').should.be.false;
})
})
})
})

0 comments on commit 05d95f0

Please sign in to comment.