|
9372 | 9372 | function debounce(func, wait, options) {
|
9373 | 9373 | var lastArgs,
|
9374 | 9374 | lastThis,
|
| 9375 | + maxWait, |
9375 | 9376 | result,
|
9376 | 9377 | timerId,
|
9377 | 9378 | lastCallTime = 0,
|
9378 | 9379 | lastInvokeTime = 0,
|
9379 | 9380 | leading = false,
|
9380 |
| - maxWait = false, |
| 9381 | + maxing = false, |
9381 | 9382 | trailing = true;
|
9382 | 9383 |
|
9383 | 9384 | if (typeof func != 'function') {
|
|
9386 | 9387 | wait = toNumber(wait) || 0;
|
9387 | 9388 | if (isObject(options)) {
|
9388 | 9389 | 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; |
9390 | 9392 | trailing = 'trailing' in options ? !!options.trailing : trailing;
|
9391 | 9393 | }
|
9392 | 9394 |
|
|
9414 | 9416 | timeSinceLastInvoke = time - lastInvokeTime,
|
9415 | 9417 | result = wait - timeSinceLastCall;
|
9416 | 9418 |
|
9417 |
| - return maxWait === false ? result : nativeMin(result, maxWait - timeSinceLastInvoke); |
| 9419 | + return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result; |
9418 | 9420 | }
|
9419 | 9421 |
|
9420 | 9422 | function shouldInvoke(time) {
|
|
9425 | 9427 | // trailing edge, the system time has gone backwards and we're treating
|
9426 | 9428 | // it as the trailing edge, or we've hit the `maxWait` limit.
|
9427 | 9429 | return (!lastCallTime || (timeSinceLastCall >= wait) ||
|
9428 |
| - (timeSinceLastCall < 0) || (maxWait !== false && timeSinceLastInvoke >= maxWait)); |
| 9430 | + (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait)); |
9429 | 9431 | }
|
9430 | 9432 |
|
9431 | 9433 | function timerExpired() {
|
|
9474 | 9476 | if (timerId === undefined) {
|
9475 | 9477 | return leadingEdge(lastCallTime);
|
9476 | 9478 | }
|
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 | + } |
9481 | 9485 | }
|
9482 | 9486 | if (timerId === undefined) {
|
9483 | 9487 | timerId = setTimeout(timerExpired, wait);
|
|
14698 | 14702 | object = this;
|
14699 | 14703 | methodNames = baseFunctions(source, keys(source));
|
14700 | 14704 | }
|
14701 |
| - var chain = (isObject(options) && 'chain' in options) ? options.chain : true, |
| 14705 | + var chain = !(isObject(options) && 'chain' in options) || !!options.chain, |
14702 | 14706 | isFunc = isFunction(object);
|
14703 | 14707 |
|
14704 | 14708 | arrayEach(methodNames, function(methodName) {
|
|
0 commit comments