Skip to content

Commit 769a494

Browse files
committedDec 6, 2020
throttle cleanup
1 parent 03f9781 commit 769a494

6 files changed

+23
-26
lines changed
 

‎modules/debounce.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import now from './now.js';
66
// triggered at the beginning of the sequence instead of at the end.
77
export default function debounce(func, wait, immediate) {
88
var timeout, timestamp, args, result, context;
9-
var later = function () {
9+
var later = function() {
1010
var last = now() - timestamp;
1111
if (wait > last) {
1212
timeout = setTimeout(later, wait - last);
@@ -15,8 +15,8 @@ export default function debounce(func, wait, immediate) {
1515
if (!immediate) result = func.apply(context, args);
1616
}
1717
};
18-
19-
var debounced = function () {
18+
// Remove timer for immediate, samme as for throttle
19+
var debounced = function() {
2020
var callNow = immediate && !timeout;
2121
context = this;
2222
args = [].slice.call(arguments, 0);
@@ -26,7 +26,7 @@ export default function debounce(func, wait, immediate) {
2626
return result;
2727
}
2828

29-
debounced.cancel = function () {
29+
debounced.cancel = function() {
3030
clearTimeout(timeout);
3131
timeout = null;
3232
};

‎modules/throttle.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export default function throttle(func, wait, options) {
1414
previous = options.leading === false ? 0 : now();
1515
timeout = null;
1616
result = func.apply(context, args);
17-
if (!timeout) context = args = null;
1817
};
1918

2019
var throttled = function() {
@@ -23,14 +22,14 @@ export default function throttle(func, wait, options) {
2322
var remaining = wait - (_now - previous);
2423
context = this;
2524
args = arguments;
26-
if (remaining <= 0 || remaining > wait) {
25+
if (remaining <= 0) {
2726
if (timeout) {
2827
clearTimeout(timeout);
2928
timeout = null;
3029
}
3130
previous = _now;
3231
result = func.apply(context, args);
33-
if (!timeout) context = args = null;
32+
//if (!timeout) context = args = null;
3433
} else if (!timeout && options.trailing !== false) {
3534
timeout = setTimeout(later, remaining);
3635
}
@@ -40,7 +39,7 @@ export default function throttle(func, wait, options) {
4039
throttled.cancel = function() {
4140
clearTimeout(timeout);
4241
previous = 0;
43-
timeout = context = args = null;
42+
timeout = null;
4443
};
4544

4645
return throttled;

‎underscore-esm.js

+7-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎underscore-esm.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎underscore.js

+7-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎underscore.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.