Reduce debounce redundancy for executing bound function

This commit is contained in:
Graeme Yeates
2015-06-23 13:04:31 -04:00
committed by jdalton
parent 04701cd69e
commit 1fcaa481be

View File

@@ -7821,38 +7821,31 @@
maxTimeoutId = timeoutId = trailingCall = undefined;
}
function delayed() {
var remaining = wait - (now() - stamp);
if (remaining <= 0 || remaining > wait) {
if (maxTimeoutId) {
clearTimeout(maxTimeoutId);
function executeBoundFunction(shouldExecute, clearTimeoutId) {
if (clearTimeoutId) {
clearTimeout(clearTimeoutId);
}
var isCalled = trailingCall;
maxTimeoutId = timeoutId = trailingCall = undefined;
if (isCalled) {
if (shouldExecute) {
lastCalled = now();
result = func.apply(thisArg, args);
if (!timeoutId && !maxTimeoutId) {
args = thisArg = undefined;
}
}
}
function delayed() {
var remaining = wait - (now() - stamp);
if (remaining <= 0 || remaining > wait) {
executeBoundFunction(trailingCall, maxTimeoutId);
} else {
timeoutId = setTimeout(delayed, remaining);
}
}
function maxDelayed() {
if (timeoutId) {
clearTimeout(timeoutId);
}
maxTimeoutId = timeoutId = trailingCall = undefined;
if (trailing || (maxWait !== wait)) {
lastCalled = now();
result = func.apply(thisArg, args);
if (!timeoutId && !maxTimeoutId) {
args = thisArg = undefined;
}
}
executeBoundFunction(trailing || (maxWait !== wait), timeoutId);
}
function debounced() {