Fix failing debounce test.

This commit is contained in:
John-David Dalton
2016-04-13 18:17:07 -07:00
parent 44b9b085c0
commit 49f8aa4289

View File

@@ -9372,12 +9372,13 @@
function debounce(func, wait, options) { function debounce(func, wait, options) {
var lastArgs, var lastArgs,
lastThis, lastThis,
maxWait,
result, result,
timerId, timerId,
lastCallTime = 0, lastCallTime = 0,
lastInvokeTime = 0, lastInvokeTime = 0,
leading = false, leading = false,
maxWait = false, maxing = false,
trailing = true; trailing = true;
if (typeof func != 'function') { if (typeof func != 'function') {
@@ -9386,7 +9387,8 @@
wait = toNumber(wait) || 0; wait = toNumber(wait) || 0;
if (isObject(options)) { if (isObject(options)) {
leading = !!options.leading; leading = !!options.leading;
maxWait = 'maxWait' in options && nativeMax(toNumber(options.maxWait) || 0, wait); maxing = 'maxWait' in options;
maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
trailing = 'trailing' in options ? !!options.trailing : trailing; trailing = 'trailing' in options ? !!options.trailing : trailing;
} }
@@ -9414,7 +9416,7 @@
timeSinceLastInvoke = time - lastInvokeTime, timeSinceLastInvoke = time - lastInvokeTime,
result = wait - timeSinceLastCall; result = wait - timeSinceLastCall;
return maxWait === false ? result : nativeMin(result, maxWait - timeSinceLastInvoke); return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;
} }
function shouldInvoke(time) { function shouldInvoke(time) {
@@ -9425,7 +9427,7 @@
// trailing edge, the system time has gone backwards and we're treating // trailing edge, the system time has gone backwards and we're treating
// it as the trailing edge, or we've hit the `maxWait` limit. // it as the trailing edge, or we've hit the `maxWait` limit.
return (!lastCallTime || (timeSinceLastCall >= wait) || return (!lastCallTime || (timeSinceLastCall >= wait) ||
(timeSinceLastCall < 0) || (maxWait !== false && timeSinceLastInvoke >= maxWait)); (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
} }
function timerExpired() { function timerExpired() {
@@ -9474,10 +9476,12 @@
if (timerId === undefined) { if (timerId === undefined) {
return leadingEdge(lastCallTime); return leadingEdge(lastCallTime);
} }
// Handle invocations in a tight loop. if (maxing) {
clearTimeout(timerId); // Handle invocations in a tight loop.
timerId = setTimeout(timerExpired, wait); clearTimeout(timerId);
return invokeFunc(lastCallTime); timerId = setTimeout(timerExpired, wait);
return invokeFunc(lastCallTime);
}
} }
if (timerId === undefined) { if (timerId === undefined) {
timerId = setTimeout(timerExpired, wait); timerId = setTimeout(timerExpired, wait);
@@ -14698,7 +14702,7 @@
object = this; object = this;
methodNames = baseFunctions(source, keys(source)); methodNames = baseFunctions(source, keys(source));
} }
var chain = (isObject(options) && 'chain' in options) ? options.chain : true, var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
isFunc = isFunction(object); isFunc = isFunction(object);
arrayEach(methodNames, function(methodName) { arrayEach(methodNames, function(methodName) {