mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Reduce debounce redundancy for executing bound function
This commit is contained in:
@@ -7821,32 +7821,12 @@
|
||||
maxTimeoutId = timeoutId = trailingCall = undefined;
|
||||
}
|
||||
|
||||
function delayed() {
|
||||
var remaining = wait - (now() - stamp);
|
||||
if (remaining <= 0 || remaining > wait) {
|
||||
if (maxTimeoutId) {
|
||||
clearTimeout(maxTimeoutId);
|
||||
}
|
||||
var isCalled = trailingCall;
|
||||
maxTimeoutId = timeoutId = trailingCall = undefined;
|
||||
if (isCalled) {
|
||||
lastCalled = now();
|
||||
result = func.apply(thisArg, args);
|
||||
if (!timeoutId && !maxTimeoutId) {
|
||||
args = thisArg = undefined;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
timeoutId = setTimeout(delayed, remaining);
|
||||
}
|
||||
}
|
||||
|
||||
function maxDelayed() {
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
function executeBoundFunction(shouldExecute, clearTimeoutId) {
|
||||
if (clearTimeoutId) {
|
||||
clearTimeout(clearTimeoutId);
|
||||
}
|
||||
maxTimeoutId = timeoutId = trailingCall = undefined;
|
||||
if (trailing || (maxWait !== wait)) {
|
||||
if (shouldExecute) {
|
||||
lastCalled = now();
|
||||
result = func.apply(thisArg, args);
|
||||
if (!timeoutId && !maxTimeoutId) {
|
||||
@@ -7855,6 +7835,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
function delayed() {
|
||||
var remaining = wait - (now() - stamp);
|
||||
if (remaining <= 0 || remaining > wait) {
|
||||
executeBoundFunction(trailingCall, maxTimeoutId);
|
||||
} else {
|
||||
timeoutId = setTimeout(delayed, remaining);
|
||||
}
|
||||
}
|
||||
|
||||
function maxDelayed() {
|
||||
executeBoundFunction(trailing || (maxWait !== wait), timeoutId);
|
||||
}
|
||||
|
||||
function debounced() {
|
||||
args = arguments;
|
||||
stamp = now();
|
||||
|
||||
Reference in New Issue
Block a user