UNPKG

@novacbn/svelte-stork

Version:

Minimalist wrapper Svelte Stores around Stork Search, also provides customizable Components.

22 lines (21 loc) 666 B
export function debounce(func, duration = 0) { let identifier; return (...args) => { if (identifier !== undefined) { clearTimeout(identifier); identifier = undefined; } // @ts-ignore - HACK: NodeJS doesn't follow spec identifier = setTimeout(() => func(...args), duration); }; } export function throttle(func, duration = 0) { let identifier; return (...args) => { if (identifier === undefined) { func(...args); // @ts-ignore - HACK: NodeJS doesn't follow spec identifier = setTimeout(() => (identifier = undefined), duration); } }; }