UNPKG

375 BJavaScriptView Raw
1// @flow strict-local
2
3export default function throttle<TArgs: Iterable<mixed>>(
4 fn: (...args: TArgs) => mixed,
5 delay: number,
6): (...args: TArgs) => void {
7 let lastCalled: ?number;
8
9 return function throttled(...args: TArgs) {
10 if (lastCalled == null || lastCalled + delay <= Date.now()) {
11 fn.call(this, ...args);
12 lastCalled = Date.now();
13 }
14 };
15}