UNPKG

debounce-microtasks

Version:

Debounce a function using microtasks instead of timers.

37 lines 1.18 kB
/** * @module * * A simple utility to debounce a function to the next microtask. */ /** A generic typed function. */ export type Function<TArgs extends unknown[], TReturn> = (...args: TArgs) => TReturn; /** * Options for the debounceMicrotask function. */ export type Options = { /** * Maximum consecutive microtasks to push before bailing out for infinite * loops. * * @default 1000 */ debounceLimit?: number; /** * Actions to take when the debounce limit is reached. */ limitAction?: "ignore" | "invoke" | "throw"; /** * Enable this to update the arguments of the function to the latest * invocation, it uses the arguments from the first invocation by default. * * @default false */ updateArguments?: boolean; }; /** * Execute the function in the next microtask, if the function is called again * later in the event loop, push back the execution one more microtask * in the future. */ export declare const debounceMicrotask: <TArgs extends unknown[], TReturn>(fn: Function<TArgs, TReturn>, options?: Options) => Function<TArgs, void>; //# sourceMappingURL=DebounceMicrotask.d.ts.map