Skip to content

Commit c937a94

Browse files
committed
chore: use a simpler debounce function
1 parent a6fdb9c commit c937a94

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

lib/deps/underscore-plus.js

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,12 @@ export function dasherize(string) {
2323
})
2424
}
2525

26-
export function debounce(func, wait, immediate) {
27-
var timeout, result;
28-
29-
var later = function(context, args) {
30-
timeout = null;
31-
if (args) result = func.apply(context, args);
32-
};
33-
34-
var debounced = function(...args) {
35-
if (timeout) clearTimeout(timeout);
36-
if (immediate) {
37-
var callNow = !timeout;
38-
timeout = setTimeout(later, wait);
39-
if (callNow) result = func.apply(this, args);
40-
} else {
41-
timeout = setTimeout(function() {
42-
func(...args);
43-
}, wait);
44-
}
45-
46-
return result;
47-
};
48-
49-
debounced.cancel = function() {
50-
clearTimeout(timeout);
51-
timeout = null;
52-
};
53-
54-
return debounced;
26+
export function debounce(callback, wait) {
27+
let timeoutId = null
28+
return (...args) => {
29+
clearTimeout(timeoutId)
30+
timeoutId = setTimeout(() => {
31+
callback.apply(null, args)
32+
}, wait)
33+
}
5534
}

0 commit comments

Comments
 (0)