From 579c044c0086d924fd0ed3d3dc4ee0f16ed062cc Mon Sep 17 00:00:00 2001 From: danzel Date: Tue, 5 Nov 2013 10:21:32 +1300 Subject: [PATCH] Fix a potential event bug due to bad cleanup. --- spec/suites/core/EventsSpec.js | 21 +++++++++++++++++++++ src/core/Events.js | 1 + 2 files changed, 22 insertions(+) diff --git a/spec/suites/core/EventsSpec.js b/spec/suites/core/EventsSpec.js index b16429df..ff2058f6 100644 --- a/spec/suites/core/EventsSpec.js +++ b/spec/suites/core/EventsSpec.js @@ -230,6 +230,27 @@ describe('Events', function() { expect(spy.called).to.be(false); }); + it('correctly removes all listeners if given no fn', function () { + var obj = new Klass(), + spy = sinon.spy(), + foo = {}, + foo2 = {}, + foo3 = {}; + + obj.addEventListener('test', spy, foo2); + obj.addEventListener('test', spy, foo3); + + obj.removeEventListener('test'); // Removes both of the above listeners + + expect(obj.hasEventListeners('test')).to.be(false); + + //Add and remove a listener + obj.addEventListener('test', spy, foo2); + obj.removeEventListener('test', spy, foo2); + + expect(obj.hasEventListeners('test')).to.be(false); + }); + it('makes sure an event is not triggered if a listener is removed during dispatch',function() { var obj = new Klass(), spy = sinon.spy(); diff --git a/src/core/Events.js b/src/core/Events.js index 37de67e7..338a340c 100644 --- a/src/core/Events.js +++ b/src/core/Events.js @@ -90,6 +90,7 @@ L.Mixin.Events = { // clear all listeners for a type if function isn't specified delete events[type]; delete events[indexKey]; + delete events[indexLenKey]; } else { listeners = context && typeIndex ? typeIndex[contextId] : events[type];