-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathindex.d.ts
76 lines (62 loc) · 2.09 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
declare namespace pDebounce {
interface Options {
/**
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 before?: boolean;
}
}
declare const pDebounce: {
/**
[Debounce](https://css-tricks.com/debouncing-throttling-explained-examples/) promise-returning & async functions.
@param fn - Promise-returning/async function to debounce.
@param wait - Milliseconds to wait before calling `fn`.
@returns A function that delays calling `fn` until after `wait` milliseconds have elapsed since the last time it was called.
@example
```
import pDebounce from 'p-debounce';
const expensiveCall = async input => input;
const debouncedFunction = pDebounce(expensiveCall, 200);
for (const number of [1, 2, 3]) {
(async () => {
console.log(await debouncedFunction(number));
})();
}
//=> 3
//=> 3
//=> 3
```
*/
<ArgumentsType extends unknown[], ReturnType>(
fn: (...arguments: ArgumentsType) => PromiseLike<ReturnType> | ReturnType,
wait: number,
options?: pDebounce.Options
): (...arguments: ArgumentsType) => Promise<ReturnType>;
/**
Execute `function_` unless a previous call is still pending, in which case, return the pending promise. Useful, for example, to avoid processing extra button clicks if the previous one is not complete.
@param function_ - Promise-returning/async function to debounce.
@example
```
import {setTimeout as delay} from 'timers/promises';
import pDebounce from 'p-debounce';
const expensiveCall = async value => {
await delay(200);
return value;
}
const debouncedFunction = pDebounce.promise(expensiveCall);
for (const number of [1, 2, 3]) {
(async () => {
console.log(await debouncedFunction(number));
})();
}
//=> 1
//=> 1
//=> 1
```
*/
promise<ArgumentsType extends unknown[], ReturnType>(
function_: (...arguments: ArgumentsType) => PromiseLike<ReturnType> | ReturnType
): (...arguments: ArgumentsType) => Promise<ReturnType>;
};
export default pDebounce;