Skip to content

Commit

Permalink
fix .once adding .on to the listener
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanong committed Dec 1, 2013
1 parent 039f5fb commit 84a9ee4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 18 deletions.
3 changes: 0 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"emitter",
"events"
],
"dependencies": {
"indexof": "component/indexof#0.0.1"
},
"version": "1.1.0",
"license": "MIT",
"main": "index.js",
Expand Down
3 changes: 0 additions & 3 deletions component.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"repo": "component/emitter",
"description": "Event emitter",
"keywords": ["emitter", "events"],
"dependencies": {
"component/indexof": "*"
},
"version": "1.1.0",
"scripts": ["index.js"],
"license": "MIT"
Expand Down
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@

/**
* Module dependencies.
*/

var index = require('indexof');

/**
* Expose `Emitter`.
*/
Expand Down Expand Up @@ -72,7 +66,7 @@ Emitter.prototype.once = function(event, fn){
fn.apply(this, arguments);
}

fn._off = on;
on.fn = fn;
this.on(event, on);
return this;
};
Expand Down Expand Up @@ -110,8 +104,14 @@ Emitter.prototype.removeEventListener = function(event, fn){
}

// remove specific handler
var i = index(callbacks, fn._off || fn);
if (~i) callbacks.splice(i, 1);
var cb;
for (var i = 0; i < callbacks.length; i++) {
cb = callbacks[i];
if (cb === fn || cb.fn === fn) {
callbacks.splice(i, 1);
break;
}
}
return this;
};

Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"name": "emitter-component",
"description": "Event emitter",
"version": "1.1.0",
"dependencies": {
"indexof": "0.0.1"
},
"devDependencies": {
"mocha": "*",
"should": "*"
Expand Down
1 change: 1 addition & 0 deletions test/emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe('Emitter', function(){
function one() { calls.push('one'); }

emitter.once('foo', one);
emitter.once('fee', one);
emitter.off('foo', one);

emitter.emit('foo');
Expand Down

0 comments on commit 84a9ee4

Please sign in to comment.