mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Ensure maxWait isn't processed on a leading invocation ifleading is false and there isn't an max delay queued. [closes #1964]
This commit is contained in:
@@ -8683,7 +8683,7 @@
|
|||||||
lastCalled = stamp;
|
lastCalled = stamp;
|
||||||
}
|
}
|
||||||
var remaining = maxWait - (stamp - lastCalled),
|
var remaining = maxWait - (stamp - lastCalled),
|
||||||
isCalled = remaining <= 0 || remaining > maxWait;
|
isCalled = (remaining <= 0 || remaining > maxWait) && (leading || maxTimeoutId);
|
||||||
|
|
||||||
if (isCalled) {
|
if (isCalled) {
|
||||||
if (maxTimeoutId) {
|
if (maxTimeoutId) {
|
||||||
|
|||||||
11
test/test.js
11
test/test.js
@@ -3945,7 +3945,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should cancel `maxDelayed` when `delayed` is invoked', function(assert) {
|
QUnit.test('should cancel `maxDelayed` when `delayed` is invoked', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(2);
|
||||||
|
|
||||||
var done = assert.async();
|
var done = assert.async();
|
||||||
|
|
||||||
@@ -3958,9 +3958,14 @@
|
|||||||
debounced();
|
debounced();
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
debounced();
|
||||||
assert.strictEqual(callCount, 1);
|
assert.strictEqual(callCount, 1);
|
||||||
done();
|
|
||||||
}, 128);
|
}, 128);
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
assert.strictEqual(callCount, 2);
|
||||||
|
done();
|
||||||
|
}, 192);
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should invoke the `trailing` call with the correct arguments and `this` binding', function(assert) {
|
QUnit.test('should invoke the `trailing` call with the correct arguments and `this` binding', function(assert) {
|
||||||
@@ -20707,7 +20712,7 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should trigger a second throttled call as early as possible when invoked repeatedly', function(assert) {
|
QUnit.test('should trigger a second throttled call as soon as possible', function(assert) {
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
|
|
||||||
var done = assert.async();
|
var done = assert.async();
|
||||||
|
|||||||
Reference in New Issue
Block a user