remove Util invokeEach since on/off are hot functions
This commit is contained in:
parent
a628e724a1
commit
9f09f50812
@ -75,33 +75,6 @@ describe('Util', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#invokeEach', function () {
|
||||
it('calls the given method/context with each key/value and additional arguments', function () {
|
||||
var spy = sinon.spy(),
|
||||
ctx = {};
|
||||
|
||||
var result = L.Util.invokeEach({
|
||||
foo: 'bar',
|
||||
yo: 'hey'
|
||||
}, spy, ctx, 1, 2, 3);
|
||||
|
||||
expect(spy.firstCall.calledWith('foo', 'bar', 1, 2, 3)).to.be.ok();
|
||||
expect(spy.secondCall.calledWith('yo', 'hey', 1, 2, 3)).to.be.ok();
|
||||
|
||||
expect(spy.firstCall.calledOn(ctx)).to.be.ok();
|
||||
expect(spy.secondCall.calledOn(ctx)).to.be.ok();
|
||||
|
||||
expect(result).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false if the given agument is not object', function () {
|
||||
var spy = sinon.spy();
|
||||
|
||||
expect(L.Util.invokeEach('foo', spy)).to.be(false);
|
||||
expect(spy.called).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#falseFn', function () {
|
||||
it('returns false', function () {
|
||||
expect(L.Util.falseFn()).to.be(false);
|
||||
|
@ -9,7 +9,12 @@ L.Evented = L.Class.extend({
|
||||
on: function (types, fn, context) {
|
||||
|
||||
// types can be a map of types/handlers
|
||||
if (L.Util.invokeEach(types, this.on, this, fn, context)) { return this; }
|
||||
if (typeof types === 'object') {
|
||||
for (var type in types) {
|
||||
this.on(type, types[type], fn);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
var events = this[eventsKey] = this[eventsKey] || {},
|
||||
contextId = context && context !== this && L.stamp(context),
|
||||
@ -63,7 +68,12 @@ L.Evented = L.Class.extend({
|
||||
return this.clearAllEventListeners();
|
||||
}
|
||||
|
||||
if (L.Util.invokeEach(types, this.off, this, fn, context)) { return this; }
|
||||
if (typeof types === 'object') {
|
||||
for (var type in types) {
|
||||
this.off(type, types[type], fn);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
var events = this[eventsKey],
|
||||
contextId = context && context !== this && L.stamp(context),
|
||||
@ -167,7 +177,12 @@ L.Evented = L.Class.extend({
|
||||
|
||||
once: function (types, fn, context) {
|
||||
|
||||
if (L.Util.invokeEach(types, this.addOneTimeEventListener, this, fn, context)) { return this; }
|
||||
if (typeof types === 'object') {
|
||||
for (var type in types) {
|
||||
this.once(type, types[type], fn);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
var handler = L.bind(function () {
|
||||
this
|
||||
|
@ -47,21 +47,6 @@ L.Util = {
|
||||
};
|
||||
}()),
|
||||
|
||||
invokeEach: function (obj, method, context) {
|
||||
var i, args;
|
||||
|
||||
if (typeof obj === 'object') {
|
||||
args = Array.prototype.slice.call(arguments, 3);
|
||||
|
||||
for (i in obj) {
|
||||
method.apply(context, [i, obj[i]].concat(args));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
limitExecByInterval: function (fn, time, context) {
|
||||
var lock, execOnUnlock;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user