forked from abner/for-legacy-web
Port settings.
This commit is contained in:
15
src/lib/debounce.ts
Normal file
15
src/lib/debounce.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export function debounce(cb: Function, duration: number) {
|
||||
// Store the timer variable.
|
||||
let timer: number;
|
||||
// This function is given to React.
|
||||
return (...args: any[]) => {
|
||||
// Get rid of the old timer.
|
||||
clearTimeout(timer);
|
||||
// Set a new timer.
|
||||
timer = setTimeout(() => {
|
||||
// Instead calling the new function.
|
||||
// (with the newer data)
|
||||
cb(...args);
|
||||
}, duration);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user