type Cancellable> = ((...args: A) => void) & {
cancel(finish?: boolean): void;
};
/** returns a debounced function that only runs after `delay` milliseconds
* of quiet-time.
* The returned function also has a nice `.cancel()` method.
*/
declare const debounce: {
(func: (...args: A) => void, delay: number, immediate?: boolean): Cancellable;
/** Sugar to produce a dynamic debounced function that accepts its contents/behavior at call time.
*
* Usage:
*
* const myDebouncer = debounce.d(500);
* myDebouncer(() => { alert('Hello world'); });
* myDebouncer(() => { alert('I mean: Howdy world!'); });
* myDebouncer((name) => { alert('Wazzap ' + name); }, 'world');
*/
d(delay: number, immediate?: boolean): Cancellable<[fn: (...args: any[]) => void, ...args: any[]]>;
};
/** /
const debouncer = debounce.d(20, true);
const add = (a: number, b: number) => a * b;
// FIXME: This test should fail!
// $ExpectError
debouncer(add, 'a', 'b');
// $ExpectError
debouncer('a', 'b');
/**/
export default debounce;