type Function = (...args: T) => S; type DebouncedFunction = { (...args: Input): void; cancel: () => void; now: (...args: Input) => Output; }; /** * Debounce a function call. * * @description * Function calls are delayed by `wait` milliseconds and only one out of * multiple function calls is executed. * * @param fn - Function to be debounced * @param wait - Number of milliseconds to debounce the function call. * @return Debounced function */ export declare const debounce: (fn: Function, wait: number) => DebouncedFunction; /** * Get a promise that resolves after the next `n` animation frames * @param n - Number of animation frames to wait * @return A promise that resolves after the next `n` animation frames */ export declare const nextAnimationFrame: (n?: number) => Promise; type ThrottledFunction = { (...args: Input): void; reset: () => void; now: (...args: Input) => Output; }; /** * Throttle a function * * @description * A throttled function will only ever be called every `wait` milliseconds at * most. * * @param fn - Function to be throttled * @param wait - Number of milliseconds calls are throttled * @return Throttled function */ export declare const throttle: (fn: Function, wait: number) => ThrottledFunction; type ThrottledAndDebouncedFunction = { (...args: Input): void; reset: () => void; cancel: () => void; now: (...args: Input) => Output; }; /** * Throttle and debounce a function call * * Throttling a function call means that the function is called at most every * `interval` milliseconds no matter how frequently you trigger a call. * Debouncing a function call means that the function is called the earliest * after `finalWait` milliseconds wait time where the function was not called. * Combining the two ensures that the function is called at most every * `interval` milliseconds and is ensured to be called with the very latest * arguments after after `finalWait` milliseconds wait time at the end. * * The following imaginary scenario describes the behavior: * * MS | throttleTime=3 and debounceTime=3 * 1. y(f, 3, 3)(args1) => f(args1) called * 2. y(f, 3, 3)(args2) => call ignored due to throttling * 3. y(f, 3, 3)(args3) => call ignored due to throttling * 4. y(f, 3, 3)(args4) => f(args4) called * 5. y(f, 3, 3)(args5) => all ignored due to throttling * 6. No call => nothing * 7. No call => f(args5) called due to debouncing * * @param fn - Function to be throttled and debounced * @param throttleTime - Throttle intevals in milliseconds * @param debounceTime - Debounce wait time in milliseconds. By default this is * the same as `throttleTime`. * @return Throttled and debounced function */ export declare const throttleAndDebounce: (fn: Function, throttleTime: number, debounceTime?: number) => ThrottledAndDebouncedFunction; /** * Promise that resolves after some time * @param msec - Time in milliseconds until the promise is resolved * @return Promise resolving after `msec` milliseconds */ export declare const wait: (msec: number) => Promise; /** * Synonym for `wait()` because `await timeout(250)` reads nicer */ export declare const timeout: (msec: number) => Promise; export {};