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:
John-David Dalton
2016-02-11 00:16:43 -08:00
parent d58d6f45cc
commit 1c47acd040
2 changed files with 9 additions and 4 deletions

View File

@@ -8683,7 +8683,7 @@
lastCalled = stamp;
}
var remaining = maxWait - (stamp - lastCalled),
isCalled = remaining <= 0 || remaining > maxWait;
isCalled = (remaining <= 0 || remaining > maxWait) && (leading || maxTimeoutId);
if (isCalled) {
if (maxTimeoutId) {

View File

@@ -3945,7 +3945,7 @@
});
QUnit.test('should cancel `maxDelayed` when `delayed` is invoked', function(assert) {
assert.expect(1);
assert.expect(2);
var done = assert.async();
@@ -3958,9 +3958,14 @@
debounced();
setTimeout(function() {
debounced();
assert.strictEqual(callCount, 1);
done();
}, 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) {
@@ -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);
var done = assert.async();