Skip to content

Commit 0304586

Browse files
authored
Create debounce.js
1 parent 10cb19b commit 0304586

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

debounce.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
invoke handler only if it is an action
3+
was not taken in the last `delay` seconds
4+
examples: typeahead
5+
*/
6+
const debounce = (handler, delay) => {
7+
let debounceHandler = null;
8+
return function () {
9+
clearTimeout(timeoutHandler);
10+
debounceHandler = setTimeout(() => {
11+
handler.apply(this, arguments);
12+
}, delay);
13+
};
14+
}

0 commit comments

Comments
 (0)