-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
364 lines (277 loc) · 8.35 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
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
export type SharingType = 'hard'|'weak';
/** global * */
export interface OriginAgent<S = any> {
state: S;
[key: string]: any;
}
export type Model<S = any> = OriginAgent<S>;
export interface Env {
expired?: boolean;
}
export declare type Runtime<T extends Record<string, any>=any> = {
methodName: string|number;
args?: any[];
agent: T;
model: T;
env: Env;
cache: { [key: string]: any };
mapModel:(handler:ProxyHandler<T>)=>T;
};
export declare type StateProcess = <T = any>(result: any) => any;
export declare type NextProcess = (next: StateProcess) => StateProcess;
export declare type MiddleWare = <T>(runtime: Runtime<T>) => NextProcess | void;
export interface LifecycleEnv extends Env {
expire: () => void;
rebuild: () => void;
}
export interface LifecycleRuntime<T = any> extends Runtime<T> {
env: LifecycleEnv;
}
export declare type LifecycleMiddleWare = (
<T>(runtime: LifecycleRuntime<T>
) => NextProcess | void) & {
lifecycle: true;
};
export declare type Action<T=unknown> = {
type: string;
prevState:T;
state: T;
params:unknown[];
};
type Dispatch = (action: Action) => any;
export type Reducer<S, A> = (state: S, action: A) => S;
interface ReducerPadding<
S = any,
T extends OriginAgent<S> = OriginAgent<S>
> {
agent: T;
connect: (dispatch?: Dispatch) => void;
disconnect:()=>void
}
type AgentRunner<T> = {
run:<R>(callback:(agent:T)=>any)=>R
};
export type AgentReducer<
S = any,
T extends OriginAgent<S> = any
> = Reducer<S, Action> & ReducerPadding<S, T>;
export declare type Factory<
S,
T extends OriginAgent<S> = OriginAgent<S>
> = (...args:any[])=>T|{new ():T};
export declare type SharingRef<
S,
T extends Model<S>= Model<S>,
> = {
current:T,
initial:(...args:any[])=>T
};
export declare function sharing<
S,
T extends Model<S> = Model<S>
>(factory:Factory<S, T>): SharingRef<S, T>;
export declare function weakSharing<
S,
T extends Model<S>=Model<S>
>(
factory:Factory<S, T>,
):SharingRef<S, T>;
export declare function create<
S,
T extends Model<S> = Model<S>
>(
model: T | { new (): T },
...middleWares: (MiddleWare & { lifecycle?: boolean })[]
): AgentReducer<S, T>;
export declare function connect<
S,
T extends Model<S> = Model<S>
>(
model: T | { new (): T },
...middleWares: (MiddleWare & { lifecycle?: boolean })[]
):AgentRunner<T>
export declare enum DefaultActionType {
DX_MUTE_STATE = '@@AGENT_MUTE_STATE'
}
export declare function isAgent<T extends Record<string, any>>(data: T): boolean;
export declare function getSharingType<
S,
T extends Model<S>=Model<S>
>(model:T):undefined|SharingType;
declare type MiddleWareAbleFunction = (...args: any[]) => any;
declare type MiddleWareAble<S, T extends OriginAgent<S>> =
MiddleWareAbleFunction | T | ({ new (): T });
declare type DecoratorCaller = (target: any, p?: string)=>any;
declare type MethodDecoratorCaller = (target: any, p: string)=>any;
export declare function withMiddleWare<S, T extends OriginAgent<S>>(
agent: T,
...mdws: (MiddleWare | LifecycleMiddleWare)[]
): T;
export declare const middleWare: <
S,
T extends Model<S>
>(
callOrMiddleWare: MiddleWare | LifecycleMiddleWare | MiddleWareAble<S, T>,
...mdw: (MiddleWare | LifecycleMiddleWare)[]
) => DecoratorCaller;
/** middleWares * */
export declare function defaultMiddleWare<T>(runtime: Runtime): NextProcess;
export declare function applyMiddleWares(
...middleWares: (MiddleWare | LifecycleMiddleWare)[]
): MiddleWare & {
lifecycle: boolean;
};
export declare const toLifecycleMiddleWare: (lifecycleMiddleWare: Omit<LifecycleMiddleWare, 'lifecycle'> & {
lifecycle?: boolean;
}) => LifecycleMiddleWare;
export declare class LifecycleMiddleWares {
static takeLatest(): LifecycleMiddleWare;
}
export declare type EffectCallback<S> = (
prevState:S, nextState:S, methodName:string|null, action:Action|null
)=>void|(()=>void);
declare type EffectWrap<S=any, T extends Model<S>=Model> = {
unmount:()=>void,
update:(nextCallback:EffectCallback<S>)=>void,
}
export declare function addEffect<S=any, T extends Model<S> = Model>(
effectCallback:EffectCallback<S>,
target:T,
method?:keyof T|((...args:any[])=>any)|'*',
):EffectWrap<S, T>;
export declare function effect<S=any, T extends Model<S>=Model>(
method:(()=>((...args:any[])=>any)|(((...args:any[])=>any)[]))|'*',
):MethodDecoratorCaller;
export type ErrorListener = (error:any, methodName:string)=>any;
export type Avatar<T extends Record<string, any>> = {
current:T,
implement:(impl:Partial<T>)=>()=>void;
};
export declare function avatar<
T extends Record<string, unknown>
>(interfaces:T):Avatar<T>;
export declare function experience():void;
export declare function strict():DecoratorCaller;
export type ActMethodDecoratorCaller = <S, T extends Model<S>>(
target: T,
p: string
) => TypedPropertyDescriptor<(...args: any[]) => T['state']>;
export declare function act():ActMethodDecoratorCaller;
export type LaunchHandler = {
shouldLaunch?:()=>boolean,
shouldUpdate?:()=>boolean,
didLaunch?:(result:any)=>any,
invoke?:(method:(...args:any[])=>any)=>((...args:any[])=>any);
}
export type FlowRuntime = {
state:Record<string, any>,
resolve:(result:any)=>any;
reject:(error:any)=>any
};
export type WorkFlow = (runtime:FlowRuntime)=>LaunchHandler;
type BlockFlowConfig = {timeout?:number};
type DebounceFlowConfig = {time:number, leading?:boolean};
declare type FlowFn =((...flows:WorkFlow[])=>MethodDecoratorCaller)&{
force:<S=any, T extends Model<S>=Model<S>>(target:T, ...workFlows:WorkFlow[])=>T,
error:<
S=any,
T extends Model<S>=Model<S>
>(model:T, listener:ErrorListener)=>(()=>void)
}
export declare const flow:FlowFn;
export class Flows {
static promise():WorkFlow;
static latest():WorkFlow;
static debounce(ms:number|DebounceFlowConfig, leading?:boolean):WorkFlow;
static block(timeout?:number|BlockFlowConfig):WorkFlow;
static submitOnce():WorkFlow;
}
export class MiddleWares {
static takeNothing(): MiddleWare;
/**
* @deprecated
*/
static takeNone(): MiddleWare;
static takePromiseResolve(): MiddleWare;
static takeAssignable(): MiddleWare;
/**
* @deprecated
*/
static takeBlock(blockMs?: number): MiddleWare;
static takeUnstableBlock(blockMs?: number): MiddleWare;
/**
* @deprecated
* @param waitMs
*/
static takeThrottle(waitMs: number): MiddleWare;
static takeUnstableThrottle(waitMs: number): MiddleWare;
/**
* @deprecated
* @param waitMs
* @param opt
*/
static takeDebounce(waitMs: number, opt?: {
leading?: boolean;
}): MiddleWare;
static takeUnstableDebounce(waitMs: number, opt?: {
leading?: boolean;
}): MiddleWare;
}
export class MiddleWarePresets {
static takeNothing(): MiddleWare;
/**
* @deprecated
*/
static takeNone(): MiddleWare;
static takeAssignable(): MiddleWare;
static takePromiseResolve(): MiddleWare;
static takeLatest(): MiddleWare;
/**
* @deprecated
* @param ms
*/
static takeBlock(ms?: number): MiddleWare;
static takeUnstableBlock(ms?: number):MiddleWare;
/**
* @deprecated
* @param wait
*/
static takeThrottle(wait: number): MiddleWare;
static takeUnstableThrottle(wait: number): MiddleWare;
/**
* @deprecated
* @param wait
* @param opt
*/
static takeDebounce(wait: number, opt?: {
leading?: boolean;
}): MiddleWare;
static takeUnstableDebounce(wait: number, opt?: {
leading?: boolean;
}): MiddleWare;
static takePromiseResolveAssignable(): MiddleWare;
/**
* @deprecated
* @param ms
*/
static takeLazyAssignable(ms: number): MiddleWare;
static takeLatestAssignable(): MiddleWare;
static takeBlockAssignable(ms?: number): MiddleWare;
/**
* @deprecated
* @param wait
*/
static takeThrottleAssignable(wait: number): MiddleWare;
static takeUnstableThrottleAssignable(wait: number): MiddleWare;
/**
* @deprecated
* @param wait
* @param opt
*/
static takeDebounceAssignable(wait: number, opt?: {
leading?: boolean;
}): MiddleWare;
static takeUnstableDebounceAssignable(wait: number, opt?: {
leading?: boolean;
}): MiddleWare;
}