8000 Fix failing debounce test. · lodash/lodash@49f8aa4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 49f8aa4

Browse files
committed
Fix failing debounce test.
1 parent 44b9b08 commit 49f8aa4

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lodash.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9372,12 +9372,13 @@
93729372
function debounce(func, wait, options) {
93739373
var lastArgs,
93749374
lastThis,
9375+
maxWait,
93759376
result,
93769377
timerId,
93779378
lastCallTime = 0,
93789379
lastInvokeTime = 0,
93799380
leading = false,
9380-
maxWait = false,
9381+
maxing = false,
93819382
trailing = true;
93829383

93839384
if (typeof func != 'function') {
@@ -9386,7 +9387,8 @@
93869387
wait = toNumber(wait) || 0;
93879388
if (isObject(options)) {
93889389
leading = !!options.leading;
9389-
maxWait = 'maxWait' in options && nativeMax(toNumber(options.maxWait) || 0, wait);
9390+
maxing = 'maxWait' in options;
9391+
maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
93909392
trailing = 'trailing' in options ? !!options.trailing : trailing;
93919393
}
93929394

@@ -9414,7 +9416,7 @@
94149416
timeSinceLastInvoke = time - lastInvokeTime,
94159417
result = wait - timeSinceLastCall;
94169418

9417-
return maxWait === false ? result : nativeMin(result, maxWait - timeSinceLastInvoke);
9419+
return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;
94189420
}
94199421

94209422
function shouldInvoke(time) {
@@ -9425,7 +9427,7 @@
94259427
// trailing edge, the system time has gone backwards and we're treating
94269428
// it as the trailing edge, or we've hit the `maxWait` limit.
94279429
return (!lastCallTime || (timeSinceLastCall >= wait) ||
9428-
(timeSinceLastCall < 0) || (maxWait !== false && timeSinceLastInvoke >= maxWait));
9430+
(timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
94299431
}
94309432

94319433
function timerExpired() {
@@ -9474,10 +9476,12 @@
94749476
if (timerId === undefined) {
94759477
return leadingEdge(lastCallTime);
94769478
}
9477-
// Handle invocations in a tight loop.
9478-
clearTimeout(timerId);
9479-
timerId = setTimeout(timerExpired, wait);
9480-
return invokeFunc(lastCallTime);
9479+
if (maxing) {
9480+
// Handle invocations in a tight loop.
9481+
clearTimeout(timerId);
9482+
timerId = setTimeout(timerExpired, wait);
9483+
return invokeFunc(lastCallTime);
9484+
}
94819485
}
94829486
if (timerId === undefined) {
94839487
timerId = setTimeout(timerExpired, wait);
@@ -14698,7 +14702,7 @@
1469814702
object = this;
1469914703
methodNames = baseFunctions(source, keys(source));
1470014704
}
14701-
var chain = (isObject(options) && 'chain' in options) ? options.chain : true,
14705+
var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
1470214706
isFunc = isFunction(object);
1470314707

1470414708
arrayEach(methodNames, function(methodName) {

0 commit comments

Comments
 (0)
0