add Util.invokeEach for hash arguments in event methods

This commit is contained in:
Vladimir Agafonkin 2013-04-19 17:23:14 +03:00
commit a5e8bc0f49
2 changed files with 44 additions and 0 deletions

View File

@ -74,6 +74,33 @@ 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 () { describe('#falseFn', function () {
it('returns false', function () { it('returns false', function () {
expect(L.Util.falseFn()).to.be(false); expect(L.Util.falseFn()).to.be(false);

View File

@ -33,6 +33,23 @@ L.Util = {
}; };
}()), }()),
invokeEach: function (obj, method, context) {
var i, args;
if (typeof obj === 'object') {
args = Array.prototype.slice.call(arguments, 3);
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
method.apply(context, [i, obj[i]].concat(args));
}
}
return true;
}
return false;
},
limitExecByInterval: function (fn, time, context) { limitExecByInterval: function (fn, time, context) {
var lock, execOnUnlock; var lock, execOnUnlock;