Krinkle has uploaded a new change for review.
https://gerrit.wikimedia.org/r/141957
Change subject: EventEmitter: Remove dead code that claims to prevent double
bindins
......................................................................
EventEmitter: Remove dead code that claims to prevent double bindins
The documentation claims that if binding the same event name and
callback multiple times, the later ones are ignored.
However this isn't true (in fact, we have a unit test asserting
the opposite). The code that pretented to do this was broken
because it evaluated 'bindings.callback' when it should've been
evaluating 'binding.callback'. The former is always undefined.
I've considered repairing this feature (which has been broken
since the very first release), but I think it's best to drop it.
It's not really a bug either way, both are behaviours that could
be expected from an event emitter. To change this now would
break compatibility. And in retrospect I think this feature was a
mistake. It encourages bad code and would mask the error by
silently ignoring any duplicate binding.
Change-Id: I3b84484d7ce1d0c9737c0741453de24fca684e60
---
M src/EventEmitter.js
1 file changed, 1 insertion(+), 11 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/oojs/core refs/changes/57/141957/1
diff --git a/src/EventEmitter.js b/src/EventEmitter.js
index 70c024d..7e6e893 100644
--- a/src/EventEmitter.js
+++ b/src/EventEmitter.js
@@ -19,8 +19,6 @@
/**
* Add a listener to events of a specific event.
*
- * If the callback/context are already bound to the event, they will not be
bound again.
- *
* @param {string} event Type of event to listen to
* @param {Function} callback Function to call when event occurs
* @param {Array} [args] Arguments to pass to listener, will be prepended to
emitted arguments
@@ -29,7 +27,7 @@
* @chainable
*/
oo.EventEmitter.prototype.on = function ( event, callback, args, context ) {
- var i, bindings, binding;
+ var bindings;
// Validate callback
if ( typeof callback !== 'function' ) {
@@ -40,15 +38,7 @@
context = null;
}
if ( this.bindings.hasOwnProperty( event ) ) {
- // Check for duplicate callback and context for this event
bindings = this.bindings[event];
- i = bindings.length;
- while ( i-- ) {
- binding = bindings[i];
- if ( bindings.callback === callback && bindings.context
=== context ) {
- return this;
- }
- }
} else {
// Auto-initialize bindings list
bindings = this.bindings[event] = [];
--
To view, visit https://gerrit.wikimedia.org/r/141957
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3b84484d7ce1d0c9737c0741453de24fca684e60
Gerrit-PatchSet: 1
Gerrit-Project: oojs/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits