-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: #449 Reviewed-By: Ben Noordhuis <[email protected]>
- Loading branch information
1 parent
946eabd
commit fd30eb2
Showing
7 changed files
with
91 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,90 +191,90 @@ EventEmitter.prototype.once = function once(type, listener) { | |
// emits a 'removeListener' event iff the listener was removed | ||
EventEmitter.prototype.removeListener = | ||
function removeListener(type, listener) { | ||
var list, position, length, i; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Fishrock123
Contributor
|
||
|
||
if (!util.isFunction(listener)) | ||
throw TypeError('listener must be a function'); | ||
|
||
if (!this._events || !this._events[type]) | ||
return this; | ||
|
||
list = this._events[type]; | ||
length = list.length; | ||
position = -1; | ||
|
||
if (list === listener || | ||
(util.isFunction(list.listener) && list.listener === listener)) { | ||
delete this._events[type]; | ||
if (this._events.removeListener) | ||
this.emit('removeListener', type, listener); | ||
|
||
} else if (util.isObject(list)) { | ||
for (i = length; i-- > 0;) { | ||
if (list[i] === listener || | ||
(list[i].listener && list[i].listener === listener)) { | ||
position = i; | ||
break; | ||
var list, position, length, i; | ||
|
||
if (!util.isFunction(listener)) | ||
throw TypeError('listener must be a function'); | ||
|
||
if (!this._events || !this._events[type]) | ||
return this; | ||
|
||
list = this._events[type]; | ||
length = list.length; | ||
position = -1; | ||
|
||
if (list === listener || | ||
(util.isFunction(list.listener) && list.listener === listener)) { | ||
delete this._events[type]; | ||
if (this._events.removeListener) | ||
this.emit('removeListener', type, listener); | ||
|
||
} else if (util.isObject(list)) { | ||
for (i = length; i-- > 0;) { | ||
if (list[i] === listener || | ||
(list[i].listener && list[i].listener === listener)) { | ||
position = i; | ||
break; | ||
} | ||
} | ||
|
||
if (position < 0) | ||
return this; | ||
|
||
if (list.length === 1) { | ||
list.length = 0; | ||
delete this._events[type]; | ||
} else { | ||
spliceOne(list, position); | ||
} | ||
|
||
if (this._events.removeListener) | ||
this.emit('removeListener', type, listener); | ||
} | ||
} | ||
|
||
if (position < 0) | ||
return this; | ||
|
||
if (list.length === 1) { | ||
list.length = 0; | ||
delete this._events[type]; | ||
} else { | ||
spliceOne(list, position); | ||
} | ||
|
||
if (this._events.removeListener) | ||
this.emit('removeListener', type, listener); | ||
} | ||
|
||
return this; | ||
}; | ||
}; | ||
|
||
EventEmitter.prototype.removeAllListeners = | ||
function removeAllListeners(type) { | ||
var key, listeners; | ||
|
||
if (!this._events) | ||
return this; | ||
|
||
// not listening for removeListener, no need to emit | ||
if (!this._events.removeListener) { | ||
if (arguments.length === 0) | ||
this._events = {}; | ||
else if (this._events[type]) | ||
delete this._events[type]; | ||
return this; | ||
} | ||
var key, listeners; | ||
|
||
if (!this._events) | ||
return this; | ||
|
||
// not listening for removeListener, no need to emit | ||
if (!this._events.removeListener) { | ||
if (arguments.length === 0) | ||
this._events = {}; | ||
else if (this._events[type]) | ||
delete this._events[type]; | ||
return this; | ||
} | ||
|
||
// emit removeListener for all listeners on all events | ||
if (arguments.length === 0) { | ||
for (key in this._events) { | ||
if (key === 'removeListener') continue; | ||
this.removeAllListeners(key); | ||
} | ||
this.removeAllListeners('removeListener'); | ||
this._events = {}; | ||
return this; | ||
} | ||
// emit removeListener for all listeners on all events | ||
if (arguments.length === 0) { | ||
for (key in this._events) { | ||
if (key === 'removeListener') continue; | ||
this.removeAllListeners(key); | ||
} | ||
this.removeAllListeners('removeListener'); | ||
this._events = {}; | ||
return this; | ||
} | ||
|
||
listeners = this._events[type]; | ||
listeners = this._events[type]; | ||
|
||
if (util.isFunction(listeners)) { | ||
this.removeListener(type, listeners); | ||
} else if (Array.isArray(listeners)) { | ||
// LIFO order | ||
while (listeners.length) | ||
this.removeListener(type, listeners[listeners.length - 1]); | ||
} | ||
delete this._events[type]; | ||
if (util.isFunction(listeners)) { | ||
this.removeListener(type, listeners); | ||
} else if (Array.isArray(listeners)) { | ||
// LIFO order | ||
while (listeners.length) | ||
this.removeListener(type, listeners[listeners.length - 1]); | ||
} | ||
delete this._events[type]; | ||
|
||
return this; | ||
}; | ||
return this; | ||
}; | ||
|
||
EventEmitter.prototype.listeners = function listeners(type) { | ||
var ret; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oh, @bnoordhuis if only you knew my
git blame
pain because of this.