lodash: Optimize and simplify throttle. [cowboy, jddalton]

Former-commit-id: 52e19aeb8671e86a13bf54876bf1f3f1b4644437
This commit is contained in:
John-David Dalton
2012-05-01 21:11:40 -04:00
parent 8396ed3167
commit 367f0bd6a9
2 changed files with 46 additions and 19 deletions

View File

@@ -187,6 +187,31 @@
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.throttle');
(function() {
test('subsequent calls should return the result of the first call', function() {
var throttled = _.throttle(function(value) { return value; }, 100),
result = [throttled('x'), throttled('y')];
deepEqual(result, ['x', 'x']);
});
test('supports calls in a loop', function() {
var counter = 0,
throttled = _.throttle(function() { counter++; }, 100),
start = new Date,
limit = 220;
while ((new Date - start) < limit) {
throttled();
}
equal(counter, 3);
});
}());
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.toArray');
(function() {