diff options
Diffstat (limited to 'src/lib/time.ts')
-rw-r--r-- | src/lib/time.ts | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/lib/time.ts b/src/lib/time.ts new file mode 100644 index 0000000..d85e935 --- /dev/null +++ b/src/lib/time.ts @@ -0,0 +1,8 @@ +export function debounce<A extends any[]>(f: (...args: A) => void, timeout: number): (...args: A) => void { + let interval: number | undefined = undefined + + return (...args: A) => { + clearTimeout(interval) + interval = setTimeout(() => f.apply(this, args), timeout) + } +} |