1
0
Fork 0
mirror of https://github.com/kou029w/quot.git synced 2025-01-19 00:18:09 +00:00
quot/app/views/helpers/throttle.ts

21 lines
443 B
TypeScript

function throttle<Fn extends (...args: any[]) => any>(
fn: Fn,
ms: number = 333
): (...args: Parameters<Fn>) => void {
let throttledFn = () => undefined;
let throttled: boolean = false;
return (...args: Parameters<Fn>): void => {
throttledFn = () => fn(...args);
if (throttled) return;
setTimeout(() => {
throttledFn();
throttled = false;
}, ms);
throttled = true;
};
}
export default throttle;