clearEventListeners -> clearAllListeners
This commit is contained in:
parent
2d5bf783fe
commit
84ad7db070
@ -246,13 +246,15 @@ describe('Events', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("#clearEventListeners", function() {
|
describe("#clearEventListeners", function() {
|
||||||
it("clears out all events on an object", function() {
|
it("clears all registered listeners on an object", function() {
|
||||||
var spy = sinon.spy(),
|
var spy = sinon.spy(),
|
||||||
obj = new Klass();
|
obj = new Klass()
|
||||||
|
otherObj = new Klass();
|
||||||
|
|
||||||
obj.on('test', spy, obj);
|
obj.on('test', spy, obj);
|
||||||
obj.on('testTwo', spy);
|
obj.on('testTwo', spy);
|
||||||
obj.clearEventListeners();
|
obj.on('test', spy, otherObj);
|
||||||
|
obj.off();
|
||||||
|
|
||||||
obj.fire('test');
|
obj.fire('test');
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ L.Mixin = {};
|
|||||||
L.Mixin.Events = {
|
L.Mixin.Events = {
|
||||||
|
|
||||||
addEventListener: function (types, fn, context) { // (String, Function[, Object]) or (Object[, Object])
|
addEventListener: function (types, fn, context) { // (String, Function[, Object]) or (Object[, Object])
|
||||||
if (!arguments) return this.clearEventListeners();
|
|
||||||
var events = this[key] = this[key] || {},
|
var events = this[key] = this[key] || {},
|
||||||
contextId = context && L.stamp(context),
|
contextId = context && L.stamp(context),
|
||||||
type, i, len, evt,
|
type, i, len, evt,
|
||||||
@ -66,6 +65,7 @@ L.Mixin.Events = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
removeEventListener: function (types, fn, context) { // (String[, Function, Object]) or (Object[, Object])
|
removeEventListener: function (types, fn, context) { // (String[, Function, Object]) or (Object[, Object])
|
||||||
|
if (!arguments.length) return this.clearAllListeners();
|
||||||
var events = this[key],
|
var events = this[key],
|
||||||
contextId = context && L.stamp(context),
|
contextId = context && L.stamp(context),
|
||||||
type, i, len, listeners, j,
|
type, i, len, listeners, j,
|
||||||
@ -150,9 +150,8 @@ L.Mixin.Events = {
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
clearEventListeners: function() {
|
clearAllListeners: function() {
|
||||||
var events = this[key],
|
var events = this[key];
|
||||||
listeners;
|
|
||||||
|
|
||||||
var clearArray = L.bind(function(collection, type) {
|
var clearArray = L.bind(function(collection, type) {
|
||||||
for (var i = 0, len = collection.length; i < len; i++) {
|
for (var i = 0, len = collection.length; i < len; i++) {
|
||||||
@ -169,7 +168,7 @@ L.Mixin.Events = {
|
|||||||
for (var type in events) {
|
for (var type in events) {
|
||||||
if (events.hasOwnProperty(type)) {
|
if (events.hasOwnProperty(type)) {
|
||||||
if (L.Util.isArray(events[type])) clearArray(events[type], type);
|
if (L.Util.isArray(events[type])) clearArray(events[type], type);
|
||||||
else if (type.substr(-4) === '_idx') (clearObject(events[type], type));
|
else if (type.substr(-4) === '_idx') clearObject(events[type], type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
Loading…
Reference in New Issue
Block a user