Fix a potential event bug due to bad cleanup.

This commit is contained in:
danzel 2013-11-05 10:21:32 +13:00
parent 65f3b2417a
commit 579c044c00
2 changed files with 22 additions and 0 deletions

View File

@ -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();

View File

@ -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];