BlueWallet/blue_modules/debounce.ts
Marcos Rodriguez Velez 4ef3d7437b
REF: JS modules to TS
2023-10-23 12:12:11 -04:00

17 lines
530 B
TypeScript

// https://levelup.gitconnected.com/debounce-in-javascript-improve-your-applications-performance-5b01855e086
const debounce = <T extends (...args: any[]) => void>(func: T, wait: number) => {
let timeout: NodeJS.Timeout | null;
return function executedFunction(this: ThisParameterType<T>, ...args: Parameters<T>) {
const later = () => {
timeout = null;
func.apply(this, args);
};
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(later, wait);
};
};
export default debounce;