Skip to content

Commit

Permalink
Fix a potential event bug due to bad cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
danzel committed Nov 4, 2013
1 parent 65f3b24 commit 579c044
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions spec/suites/core/EventsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/core/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 579c044

Please sign in to comment.