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