From 84a9ee4ec92202c44647e479de1131487c4b6ae7 Mon Sep 17 00:00:00 2001 From: Jonathan Ong Date: Sun, 1 Dec 2013 14:24:28 -0800 Subject: [PATCH] fix .once adding .on to the listener --- bower.json | 3 --- component.json | 3 --- index.js | 18 +++++++++--------- package.json | 3 --- test/emitter.js | 1 + 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/bower.json b/bower.json index dc4aa40..341e4c6 100644 --- a/bower.json +++ b/bower.json @@ -5,9 +5,6 @@ "emitter", "events" ], - "dependencies": { - "indexof": "component/indexof#0.0.1" - }, "version": "1.1.0", "license": "MIT", "main": "index.js", diff --git a/component.json b/component.json index 54808da..27590d4 100644 --- a/component.json +++ b/component.json @@ -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" diff --git a/index.js b/index.js index dd91aa1..ad71163 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,4 @@ -/** - * Module dependencies. - */ - -var index = require('indexof'); - /** * Expose `Emitter`. */ @@ -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; }; @@ -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; }; diff --git a/package.json b/package.json index 1db87b5..25710ca 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,6 @@ "name": "emitter-component", "description": "Event emitter", "version": "1.1.0", - "dependencies": { - "indexof": "0.0.1" - }, "devDependencies": { "mocha": "*", "should": "*" diff --git a/test/emitter.js b/test/emitter.js index 02521f3..91ea483 100644 --- a/test/emitter.js +++ b/test/emitter.js @@ -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');