mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Ensure cancel resets lastCallTime and lastInvokeTime.
This commit is contained in:
18
lodash.js
18
lodash.js
@@ -9330,6 +9330,7 @@
|
|||||||
if (timerId !== undefined) {
|
if (timerId !== undefined) {
|
||||||
clearTimeout(timerId);
|
clearTimeout(timerId);
|
||||||
}
|
}
|
||||||
|
lastCallTime = lastInvokeTime = 0;
|
||||||
lastArgs = lastThis = timerId = undefined;
|
lastArgs = lastThis = timerId = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -9338,17 +9339,20 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function debounced() {
|
function debounced() {
|
||||||
|
var time = now(),
|
||||||
|
isInvoking = shouldInvoke(time);
|
||||||
|
|
||||||
lastArgs = arguments;
|
lastArgs = arguments;
|
||||||
lastThis = this;
|
lastThis = this;
|
||||||
lastCallTime = now();
|
lastCallTime = time;
|
||||||
|
|
||||||
if (timerId === undefined) {
|
if (isInvoking) {
|
||||||
return leadingEdge(lastCallTime);
|
if (timerId === undefined) {
|
||||||
}
|
return leadingEdge(lastCallTime);
|
||||||
// Check times to handle invocations in a tight loop.
|
}
|
||||||
if (shouldInvoke(lastCallTime)) {
|
// Handle invocations in a tight loop.
|
||||||
clearTimeout(timerId);
|
clearTimeout(timerId);
|
||||||
timerId = undefined;
|
timerId = setTimeout(timerExpired, wait);
|
||||||
return invokeFunc(lastCallTime);
|
return invokeFunc(lastCallTime);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -21956,10 +21956,12 @@
|
|||||||
|
|
||||||
assert.strictEqual(funced(), 1);
|
assert.strictEqual(funced(), 1);
|
||||||
funced.cancel();
|
funced.cancel();
|
||||||
|
|
||||||
assert.strictEqual(funced(), 2);
|
assert.strictEqual(funced(), 2);
|
||||||
|
funced();
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
assert.strictEqual(callCount, 2);
|
assert.strictEqual(callCount, 3);
|
||||||
done();
|
done();
|
||||||
}, 64);
|
}, 64);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user