Add debounce

This commit is contained in:
Yangshun Tay 2018-01-13 12:38:45 -08:00
parent 8120da422a
commit d0fdd0276d
1 changed files with 8 additions and 0 deletions

8
utilities/debounce.js Normal file
View File

@ -0,0 +1,8 @@
const debounce = (fn, time) => {
let timerId;
return function(...args) {
const functionCall = () => fn.apply(this, args);
clearTimeout(timerId);
timerId = setTimeout(functionCall, time);
};
};