Work around iOS7 memory trouble by not applying the contextId performance optimization when context==this. The optimization does nothing in this case anyway. Fixes #2122
This commit is contained in:
parent
80c48c5da7
commit
9fce697982
@ -190,6 +190,24 @@ describe('Events', function() {
|
|||||||
expect(spy2.called).to.be(false);
|
expect(spy2.called).to.be(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('removes listeners with context == this and a stamp originally added without one', function () {
|
||||||
|
var obj = new Klass(),
|
||||||
|
spy1 = sinon.spy(),
|
||||||
|
spy2 = sinon.spy();
|
||||||
|
|
||||||
|
obj.addEventListener('test', spy1, obj);
|
||||||
|
L.Util.stamp(obj);
|
||||||
|
obj.addEventListener('test', spy2, obj);
|
||||||
|
|
||||||
|
obj.removeEventListener('test', spy1, obj);
|
||||||
|
obj.removeEventListener('test', spy2, obj);
|
||||||
|
|
||||||
|
obj.fireEvent('test');
|
||||||
|
|
||||||
|
expect(spy1.called).to.be(false);
|
||||||
|
expect(spy2.called).to.be(false);
|
||||||
|
});
|
||||||
|
|
||||||
it('doesnt lose track of listeners when removing non existent ones', function () {
|
it('doesnt lose track of listeners when removing non existent ones', function () {
|
||||||
var obj = new Klass(),
|
var obj = new Klass(),
|
||||||
spy = sinon.spy(),
|
spy = sinon.spy(),
|
||||||
|
@ -14,7 +14,7 @@ L.Mixin.Events = {
|
|||||||
if (L.Util.invokeEach(types, this.addEventListener, this, fn, context)) { return this; }
|
if (L.Util.invokeEach(types, this.addEventListener, this, fn, context)) { return this; }
|
||||||
|
|
||||||
var events = this[eventsKey] = this[eventsKey] || {},
|
var events = this[eventsKey] = this[eventsKey] || {},
|
||||||
contextId = context && L.stamp(context),
|
contextId = context && context !== this && L.stamp(context),
|
||||||
i, len, event, type, indexKey, indexLenKey, typeIndex;
|
i, len, event, type, indexKey, indexLenKey, typeIndex;
|
||||||
|
|
||||||
// types can be a string of space-separated words
|
// types can be a string of space-separated words
|
||||||
@ -27,7 +27,7 @@ L.Mixin.Events = {
|
|||||||
};
|
};
|
||||||
type = types[i];
|
type = types[i];
|
||||||
|
|
||||||
if (context) {
|
if (contextId) {
|
||||||
// store listeners of a particular context in a separate hash (if it has an id)
|
// store listeners of a particular context in a separate hash (if it has an id)
|
||||||
// gives a major performance boost when removing thousands of map layers
|
// gives a major performance boost when removing thousands of map layers
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user