mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Improve accuracy of _.throttle.
This commit is contained in:
committed by
John-David Dalton
parent
6752d75ad0
commit
e392b8e240
@@ -8652,7 +8652,7 @@
|
|||||||
if (maxWait === false) {
|
if (maxWait === false) {
|
||||||
var leadingCall = leading && !timeoutId;
|
var leadingCall = leading && !timeoutId;
|
||||||
} else {
|
} else {
|
||||||
if (!maxTimeoutId && !leading) {
|
if (!lastCalled && !maxTimeoutId && !leading) {
|
||||||
lastCalled = stamp;
|
lastCalled = stamp;
|
||||||
}
|
}
|
||||||
var remaining = maxWait - (stamp - lastCalled),
|
var remaining = maxWait - (stamp - lastCalled),
|
||||||
|
|||||||
24
test/test.js
24
test/test.js
@@ -20635,6 +20635,30 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should trigger a second throttled call as early as possible when invoked repeatedly', function(assert) {
|
||||||
|
assert.expect(2);
|
||||||
|
|
||||||
|
var done = assert.async();
|
||||||
|
|
||||||
|
var callCount = 0;
|
||||||
|
|
||||||
|
var throttled = _.throttle(function() {
|
||||||
|
callCount++;
|
||||||
|
}, 128, { 'leading': false });
|
||||||
|
|
||||||
|
throttled();
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
assert.strictEqual(callCount, 1);
|
||||||
|
throttled();
|
||||||
|
}, 192);
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
assert.strictEqual(callCount, 2);
|
||||||
|
done();
|
||||||
|
}, 288);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test('should apply default options', function(assert) {
|
QUnit.test('should apply default options', function(assert) {
|
||||||
assert.expect(3);
|
assert.expect(3);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user