-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuse-async-effect.d.ts
121 lines (106 loc) · 2.78 KB
/
use-async-effect.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
export interface UseAsyncFnOptions {
/**
* @default []
*/
deps?: any[],
/**
* @default false
*/
combine?: boolean,
/**
* @default false
*/
cancelPrevious?: boolean,
/**
* @default 0
*/
threads?: number,
/**
* @default 0
*/
queueSize?: number,
/**
* @default false
*/
scopeArg?: boolean,
/**
* @default false
*/
states?: boolean,
/**
* @default false
*/
catch?: boolean
}
export interface UseAsyncEffectOptions {
/**
* @default false
*/
skipFirst: boolean,
/**
* @default []
*/
deps?: any[],
/**
* @default false
*/
states?: boolean,
/**
* @default false
*/
once?: boolean
}
export type CancelReason = string | Error;
export type pendingState = boolean;
export type doneState = boolean;
export type resultState = boolean;
export type errorState = boolean;
export type canceledState = boolean;
export type pausedState = boolean;
export interface AsyncEffectCancelFn {
(reason?: CancelReason): boolean,
pause: (data: any)=> boolean,
resume: (data: any)=> boolean,
0: doneState,
1: resultState,
2: errorState,
3: canceledState,
4: pausedState
}
export interface DecoratedCallback {
(...args: any[]): any
cancel: (reason?: CancelReason)=> void,
pause: (data: any)=> boolean,
resume: (data: any)=> boolean,
0: DecoratedCallback,
1: (reason?: CancelReason)=> void,
2: pendingState,
3: doneState,
4: resultState,
5: errorState,
6: canceledState,
7: pausedState
}
export type CPromiseGeneratorYield = null | PromiseLike<any> | CPromiseGeneratorYield[];
export interface CPromiseGenerator {
(...args: any[]): Generator<CPromiseGeneratorYield>
}
export interface UseAsyncDeepStateOptions {
/**
* @default true
*/
watch?: boolean;
/**
* @default true
*/
defineSetters?: boolean;
}
export function useAsyncEffect(generator: CPromiseGenerator, deps?: any[]): AsyncEffectCancelFn
export function useAsyncEffect(generator: CPromiseGenerator, options?: UseAsyncEffectOptions): AsyncEffectCancelFn
export function useAsyncCallback(generator: CPromiseGenerator, deps?: any[]): DecoratedCallback
export function useAsyncCallback(generator: CPromiseGenerator, options?: UseAsyncFnOptions): DecoratedCallback
export function useAsyncDeepState(initialValue?: object, options?: UseAsyncDeepStateOptions): [object, (newState?: object)=> Promise<unknown>|void]
export function useAsyncWatcher(...values: any): (grabPrevValue?: boolean)=> Promise<any>
export const E_REASON_UNMOUNTED: 'E_REASON_UNMOUNTED'
export const E_REASON_QUEUE_OVERFLOW: 'E_REASON_QUEUE_OVERFLOW'
export const E_REASON_RESTART: 'E_REASON_RESTART'