Urara-Blog/node_modules/.pnpm-store/v3/files/70/017cc0bd97a87cd8a74311f279b905fce198c96aaded2bf78cd10e166741f40f66cf3a0d268e5176895df8b0a865b2201e63632cc9e9c8b9832670aaf83ac1
2022-08-14 01:14:53 +08:00

34 lines
1.2 KiB
Text

interface DebounceOptions {
/**
Call the `fn` on the [leading edge of the timeout](https://css-tricks.com/debouncing-throttling-explained-examples/#article-header-id-1).
Meaning immediately, instead of waiting for `wait` milliseconds.
@default false
*/
readonly leading?: boolean;
/**
Call the `fn` on trailing edge with last used arguments. Result of call is from previous call.
@default false
*/
readonly trailing?: boolean;
}
/**
Debounce functions
@param fn - Promise-returning/async function to debounce.
@param wait - Milliseconds to wait before calling `fn`. Default value is 25ms
@returns A function that delays calling `fn` until after `wait` milliseconds have elapsed since the last time it was called.
@example
```
import { debounce } from 'perfect-debounce';
const expensiveCall = async input => input;
const debouncedFn = debounce(expensiveCall, 200);
for (const number of [1, 2, 3]) {
console.log(await debouncedFn(number));
}
//=> 3
//=> 3
//=> 3
```
*/
declare function debounce<ArgumentsT extends unknown[], ReturnT>(fn: (...args: ArgumentsT) => PromiseLike<ReturnT> | ReturnT, wait?: number, options?: DebounceOptions): (...args: ArgumentsT) => Promise<ReturnT>;
export { DebounceOptions, debounce };