forked from redux-saga/redux-saga
-
Notifications
You must be signed in to change notification settings - Fork 2
/
effects.d.ts
253 lines (196 loc) · 8.17 KB
/
effects.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import {Action} from "redux";
import {Channel, Task, Buffer, Predicate} from "./types";
type Pattern<T> = string | string[] | Predicate<T>;
interface TakeEffectDescriptor<T> {
pattern: Pattern<T>;
channel: Channel<T>;
maybe?: boolean;
}
interface TakeEffect<T> {
TAKE: TakeEffectDescriptor<T>;
}
export function take<T>(pattern: Pattern<T>): TakeEffect<T>;
export function take<T>(channel: Channel<T>,
pattern?: Pattern<T>): TakeEffect<T>;
export function takem<T>(pattern: Pattern<T>): TakeEffect<T>;
export function takem<T>(channel: Channel<T>,
pattern?: Pattern<T>): TakeEffect<T>;
interface PutEffectDescriptor<T> {
action: T;
channel: Channel<T>;
}
interface PutEffect<T> {
PUT: PutEffectDescriptor<T>;
}
export function put<T extends Action>(action: T): PutEffect<T>;
export function put<T>(channel: Channel<T>, action: T): PutEffect<T>;
type RaceEffectDescriptor = {[key: string]: Effect};
interface RaceEffect {
RACE: RaceEffectDescriptor;
}
export function race(effects: {[key: string]: Effect}): RaceEffect;
interface CallEffectDescriptor {
context: any;
fn: Function;
args: any[];
}
type CallFunc0 = () => any;
type CallFunc1<T1> = (arg1: T1) => any;
type CallFunc2<T1, T2> = (arg1: T1, arg2: T2) => any;
type CallFunc3<T1, T2, T3> = (arg1: T1, arg2: T2, arg3: T3) => any;
type CallFunc4<T1, T2, T3, T4> = (arg1: T1, arg2: T2, arg3: T3,
arg4: T4) => any;
type CallFunc5<T1, T2, T3, T4, T5> = (arg1: T1, arg2: T2, arg3: T3,
arg4: T4, arg5: T5) => any;
type CallFuncRest = (...args: any[]) => any;
type CallEffectArg<F> = F | [any, F] | {context: any, fn: F};
interface CallEffectFactory<R> {
(fn: CallEffectArg<CallFunc0>): R;
<T1>(fn: CallEffectArg<CallFunc1<T1>>,
arg1: T1): R;
<T1, T2>(fn: CallEffectArg<CallFunc2<T1, T2>>,
arg1: T1, arg2: T2): R;
<T1, T2, T3>(fn: CallEffectArg<CallFunc3<T1, T2, T3>>,
arg1: T1, arg2: T2, arg3: T3): R;
<T1, T2, T3, T4>(fn: CallEffectArg<CallFunc4<T1, T2, T3, T4>>,
arg1: T1, arg2: T2, arg3: T3, arg4: T4): R;
(fn: CallEffectArg<CallFuncRest>, ...args: any[]): R;
}
interface CallEffect {
CALL: CallEffectDescriptor;
}
export const call: CallEffectFactory<CallEffect>;
export function apply(context: any, fn: CallFunc0): CallEffect;
export function apply<T1>(context: any, fn: CallFunc1<T1>,
args: [T1]): CallEffect;
export function apply<T1, T2>(context: any, fn: CallFunc2<T1, T2>,
args: [T1, T2]): CallEffect;
export function apply<T1, T2, T3>(context: any, fn: CallFunc3<T1, T2, T3>,
args: [T1, T2, T3]): CallEffect;
export function apply<T1, T2, T3, T4>(context: any,
fn: CallFunc4<T1, T2, T3, T4>,
args: [T1, T2, T3, T4]): CallEffect;
export function apply(context: any, fn: CallFuncRest,
...args: any[]): CallEffect;
interface CpsEffect {
CPS: CallEffectDescriptor;
}
type CpsCallback = (error: any, result: any) => void;
export function cps(fn: CallEffectArg<CallFunc1<CpsCallback>>): CpsEffect;
export function cps<T1>(fn: CallEffectArg<CallFunc2<T1, CpsCallback>>,
arg1: T1): CpsEffect;
export function cps<T1, T2>(fn: CallEffectArg<CallFunc3<T1, T2, CpsCallback>>,
arg1: T1, arg2: T2): CpsEffect;
export function cps<T1, T2, T3>(
fn: CallEffectArg<CallFunc4<T1, T2, T3, CpsCallback>>,
arg1: T1, arg2: T2, arg3: T3): CpsEffect;
export function cps<T1, T2, T3, T4>(
fn: CallEffectArg<CallFunc5<T1, T2, T3, T4, CpsCallback>>,
arg1: T1, arg2: T2, arg3: T3, arg4: T4): CpsEffect;
interface ForkEffectDescriptor extends CallEffectDescriptor {
detached?: boolean;
}
interface ForkEffect {
FORK: ForkEffectDescriptor;
}
export const fork: CallEffectFactory<ForkEffect>;
export const spawn: CallEffectFactory<ForkEffect>;
interface JoinEffect {
JOIN: Task;
}
export function join(task: Task): JoinEffect;
interface CancelEffect {
CANCEL: Task;
}
export function cancel(task: Task): CancelEffect;
interface SelectEffectDescriptor {
selector(state: any, ...args: any[]): any;
args: any[];
}
interface SelectEffect {
SELECT: SelectEffectDescriptor;
}
export function select(): SelectEffect;
export function select<S>(selector: CallFunc1<S>): SelectEffect;
export function select<S, T1>(selector: CallFunc2<S, T1>,
arg1: T1): SelectEffect;
export function select<S, T1, T2>(selector: CallFunc3<S, T1, T2>,
arg1: T1, arg2: T2): SelectEffect;
export function select<S, T1, T2, T3>(selector: CallFunc4<S, T1, T2, T3>,
arg1: T1, arg2: T2, arg3: T3): SelectEffect;
export function select<S, T1, T2, T3, T4>(
selector: CallFunc5<S, T1, T2, T3, T4>,
arg1: T1, arg2: T2, arg3: T3, arg4: T4): SelectEffect;
interface ActionChannelEffectDescriptor<T> {
pattern: Pattern<T>;
buffer: Buffer<T>;
}
interface ActionChannelEffect<T> {
ACTION_CHANNEL: ActionChannelEffectDescriptor<T>;
}
export function actionChannel<T>(pattern: Pattern<T>,
buffer?: Buffer<T>): ActionChannelEffect<T>;
interface CancelledEffect {
CANCELLED: {};
}
export function cancelled(): CancelledEffect;
export type Effect =
TakeEffect<any> |
PutEffect<any> |
RaceEffect | CallEffect |
CpsEffect | ForkEffect | JoinEffect | CancelEffect | SelectEffect |
ActionChannelEffect<any> | CancelledEffect;
type HelperFunc0<A> = (action?: A) => any;
type HelperFunc1<A, T1> = (arg1: T1, action?: A) => any;
type HelperFunc2<A, T1, T2> = (arg1: T1, arg2: T2, action?: A) => any;
type HelperFunc3<A, T1, T2, T3> = (arg1: T1, arg2: T2, arg3: T3,
action?: A) => any;
type HelperFunc4<A, T1, T2, T3, T4> = (arg1: T1, arg2: T2, arg3: T3, arg4: T4,
action?: A) => any;
type HelperFuncRest<A, T1, T2, T3, T4, T5> = (arg1: T1, arg2: T2, arg3: T3,
arg4: T4, arg5: T5,
...rest: any[]) => any;
interface TakeHelper {
<A>(pattern: Pattern<A>, worker: HelperFunc0<A>): ForkEffect;
<A, T1>(pattern: Pattern<A>,
worker: HelperFunc1<A, T1>, arg1: T1): ForkEffect;
<A, T1, T2>(pattern: Pattern<A>,
worker: HelperFunc2<A, T1, T2>,
arg1: T1, arg2: T2): ForkEffect;
<A, T1, T2, T3>(pattern: Pattern<A>,
worker: HelperFunc3<A, T1, T2, T3>,
arg1: T1, arg2: T2, arg3: T3): ForkEffect;
<A, T1, T2, T3, T4>(pattern: Pattern<A>,
worker: HelperFunc4<A, T1, T2, T3, T4>,
arg1: T1, arg2: T2, arg3: T3, arg4: T4): ForkEffect;
<A, T1, T2, T3, T4, T5>(pattern: Pattern<A>,
worker: HelperFuncRest<A, T1, T2, T3, T4, T5>,
arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5,
...rest: any[]): ForkEffect;
}
interface ThrottleHelper {
<A>(ms: number, pattern: Pattern<A>, worker: HelperFunc0<A>): ForkEffect;
<A, T1>(ms: number,
pattern: Pattern<A>,
worker: HelperFunc1<A, T1>, arg1: T1): ForkEffect;
<A, T1, T2>(ms: number,
pattern: Pattern<A>,
worker: HelperFunc2<A, T1, T2>,
arg1: T1, arg2: T2): ForkEffect;
<A, T1, T2, T3>(ms: number,
pattern: Pattern<A>,
worker: HelperFunc3<A, T1, T2, T3>,
arg1: T1, arg2: T2, arg3: T3): ForkEffect;
<A, T1, T2, T3, T4>(ms: number,
pattern: Pattern<A>,
worker: HelperFunc4<A, T1, T2, T3, T4>,
arg1: T1, arg2: T2, arg3: T3, arg4: T4): ForkEffect;
<A, T1, T2, T3, T4, T5>(ms: number,
pattern: Pattern<A>,
worker: HelperFuncRest<A, T1, T2, T3, T4, T5>,
arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5,
...rest: any[]): ForkEffect;
}
export const takeEvery: TakeHelper;
export const takeLatest: TakeHelper;
export const throttle: ThrottleHelper;