[Pkg-javascript-commits] [leaflet] 176/301: Improve this test and fix removeEventListener.

Jonas Smedegaard js at moszumanska.debian.org
Mon Jan 27 22:22:49 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository leaflet.

commit fa35aba1e9c48167cfbe4ad51c0a2d609594a727
Author: danzel <danzel at localhost.geek.nz>
Date:   Tue Nov 5 10:29:52 2013 +1300

    Improve this test and fix removeEventListener.
---
 spec/suites/core/EventsSpec.js | 7 ++++++-
 src/core/Events.js             | 4 ++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/spec/suites/core/EventsSpec.js b/spec/suites/core/EventsSpec.js
index ff2058f..81241ff 100644
--- a/spec/suites/core/EventsSpec.js
+++ b/spec/suites/core/EventsSpec.js
@@ -192,20 +192,25 @@ describe('Events', function() {
 
 		it('removes listeners with context == this and a stamp originally added without one', function () {
 			var obj = new Klass(),
+				obj2 = new Klass(),
 				spy1 = sinon.spy(),
-				spy2 = sinon.spy();
+				spy2 = sinon.spy(),
+				spy3 = sinon.spy();
 
 			obj.addEventListener('test', spy1, obj);
 			L.Util.stamp(obj);
 			obj.addEventListener('test', spy2, obj);
+			obj.addEventListener('test', spy3, obj2); // So that there is a contextId based listener, otherwise removeEventListener will do correct behaviour anyway
 
 			obj.removeEventListener('test', spy1, obj);
 			obj.removeEventListener('test', spy2, obj);
+			obj.removeEventListener('test', spy3, obj2);
 
 			obj.fireEvent('test');
 
 			expect(spy1.called).to.be(false);
 			expect(spy2.called).to.be(false);
+			expect(spy3.called).to.be(false);
 		});
 
 		it('doesnt lose track of listeners when removing non existent ones', function () {
diff --git a/src/core/Events.js b/src/core/Events.js
index 338a340..cd8b17a 100644
--- a/src/core/Events.js
+++ b/src/core/Events.js
@@ -74,7 +74,7 @@ L.Mixin.Events = {
 		if (L.Util.invokeEach(types, this.removeEventListener, this, fn, context)) { return this; }
 
 		var events = this[eventsKey],
-		    contextId = context && L.stamp(context),
+		    contextId = context && context !== this && L.stamp(context),
 		    i, len, type, listeners, j, indexKey, indexLenKey, typeIndex, removed;
 
 		types = L.Util.splitWords(types);
@@ -93,7 +93,7 @@ L.Mixin.Events = {
 				delete events[indexLenKey];
 
 			} else {
-				listeners = context && typeIndex ? typeIndex[contextId] : events[type];
+				listeners = contextId && typeIndex ? typeIndex[contextId] : events[type];
 
 				if (listeners) {
 					for (j = listeners.length - 1; j >= 0; j--) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet.git



More information about the Pkg-javascript-commits mailing list