@git-temporal/git-temporal-react
Version:
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
15 lines (13 loc) • 330 B
text/typescript
// https://codeburst.io/throttling-and-debouncing-in-javascript-646d076d0a44
export function debounce(fn, delay): (args: any) => any {
let timerId;
return function(...args) {
if (timerId) {
clearTimeout(timerId);
}
timerId = setTimeout(() => {
fn(...args);
timerId = null;
}, delay);
};
}