Comparing version 0.0.2 to 0.0.3
@@ -0,1 +1,6 @@ | ||
0.0.3 / 2012-02-11 | ||
================== | ||
* `once()` now passes arguments | ||
0.0.2 / 2012-02-10 | ||
@@ -2,0 +7,0 @@ ================== |
@@ -206,7 +206,31 @@ var maxLength = 3 | ||
EventEmitter.prototype.once = function (ev, handler) { | ||
var self = this | ||
var self = this, _handler | ||
function _handler () { | ||
self.off(ev, _handler) | ||
handler() | ||
switch ( this._ev_length[ev] ) { | ||
case 0: | ||
_handler = function () { | ||
self.off(ev, _handler) | ||
handler() | ||
} | ||
break | ||
case 1: | ||
_handler = function () { | ||
self.off(ev, _handler) | ||
handler(arguments[0]) | ||
} | ||
break | ||
case 2: | ||
_handler = function () { | ||
self.off(ev, _handler) | ||
handler(arguments[0], arguments[1]) | ||
} | ||
break | ||
case 3: | ||
_handler = function () { | ||
self.off(ev, _handler) | ||
handler(arguments[0], arguments[1], arguments[2]) | ||
} | ||
break | ||
default: | ||
throw new Error('Invalid number of arguments:' + this._ev_length[ev] + ' for event: ' + ev) | ||
} | ||
@@ -213,0 +237,0 @@ _handler.handler = handler |
@@ -6,3 +6,3 @@ { | ||
, "keywords": ["event","emitter","listener"] | ||
, "version": "0.0.2" | ||
, "version": "0.0.3" | ||
, "homepage": "http://github.com/pierrec/node-ev" | ||
@@ -9,0 +9,0 @@ , "repository": { |
@@ -41,2 +41,19 @@ /* | ||
}) | ||
describe('arguments', function () { | ||
var ev = new EV(options) | ||
var args = [] | ||
it('should emit trigger the handler with all its arguments', function (done) { | ||
function handler () { | ||
args.push(arguments.length) | ||
} | ||
ev.once('match', handler) | ||
ev.emit_match(null, null) | ||
assert.deepEqual(args, [2]) | ||
done() | ||
}) | ||
}) | ||
// TODO test once([ev1,ev2], listener) | ||
}) |
# TODO | ||
* Use linked objects for handlers: | ||
this.fn | ||
this.prev | ||
this.protottype.exec = this.fn(args...); this.prev.exec(args...) | ||
* `once([event1, event2...], listener)`: mutually exclusive listeners: any event will remove the listener to the other ones | ||
* Use linked objects for handlers: | ||
this.fn | ||
this.prev | ||
this.protottype.exec = this.fn(args...); this.prev.exec(args...) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27309
845