mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-15 21:53:36 +01:00
14 lines
448 B
TypeScript
14 lines
448 B
TypeScript
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
export function debounce(fn: (...args: any[]) => void, delay = 500) {
|
|
let timer: ReturnType<typeof setTimeout>;
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const result = function (...args: any[]) {
|
|
clearTimeout(timer);
|
|
timer = setTimeout(() => fn(...args), delay);
|
|
};
|
|
result.cancel = function () {
|
|
clearTimeout(timer);
|
|
};
|
|
return result;
|
|
}
|