mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-02-18 16:47:48 +01:00
14 lines
414 B
TypeScript
14 lines
414 B
TypeScript
// biome-ignore lint/suspicious/noExplicitAny: none
|
|
export function debounce(fn: (...args: any[]) => void, delay = 500) {
|
|
let timer: ReturnType<typeof setTimeout>;
|
|
// biome-ignore lint/suspicious/noExplicitAny: none
|
|
const result = (...args: any[]) => {
|
|
clearTimeout(timer);
|
|
timer = setTimeout(() => fn(...args), delay);
|
|
};
|
|
result.cancel = () => {
|
|
clearTimeout(timer);
|
|
};
|
|
return result;
|
|
}
|