-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathindex.d.ts
145 lines (118 loc) · 3.68 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
import { Action, ActionCreator, AnyAction, StoreEnhancer, Store } from 'redux';
export interface StoreCreator {
<S, A extends Action>(
reducer: LoopReducer<S, A>,
preloadedState: S,
enhancer: StoreEnhancer<S>
): Store<S>;
}
export type Loop<S, A extends Action> = [S, CmdType<A>];
export interface LoopReducer<S, A extends Action> {
(state: S | undefined, action: AnyAction): S | Loop<S, A>;
}
export interface LiftedLoopReducer<S, A extends Action> {
(state: S | undefined, action: AnyAction): Loop<S, A>;
}
export type CmdSimulation = {
result: any,
success: boolean
};
export interface MultiCmdSimulation {
[index: number]: CmdSimulation | MultiCmdSimulation;
}
type SingleCmdSimulationFunction<A extends Action> = (simulation?: CmdSimulation) => A;
type MultiCmdSimulationFunction<A extends Action> = (simulations: MultiCmdSimulation) => A[];
export interface NoneCmd {
type: 'NONE';
simulate: SingleCmdSimulationFunction<AnyAction>;
}
export interface ListCmd<A extends Action> {
type: 'LIST';
cmds: CmdType<A>[];
sequence?: boolean;
batch?: boolean;
simulate: MultiCmdSimulationFunction<A>;
}
export interface ActionCmd<A extends Action> {
type: 'ACTION';
actionToDispatch: A;
simulate: SingleCmdSimulationFunction<A>;
}
export interface MapCmd<A extends Action> {
type: 'MAP';
tagger: ActionCreator<A>;
nestedCmd: CmdType<A>;
args: any[];
simulate: SingleCmdSimulationFunction<A> | MultiCmdSimulationFunction<A>;
}
export interface RunCmd<A extends Action> {
type: 'RUN';
func: Function;
args?: any[];
failActionCreator?: ActionCreator<A>;
successActionCreator?: ActionCreator<A>;
forceSync?: boolean;
simulate: SingleCmdSimulationFunction<A>;
}
//deprecated types
export type SequenceCmd<A extends Action> = ListCmd<A>;
export type BatchCmd<A extends Action> = ListCmd<A>;
export type CmdType<A extends Action> =
| ActionCmd<A>
| ListCmd<A>
| MapCmd<A>
| NoneCmd
| RunCmd<A>
| BatchCmd<A>
| SequenceCmd<A>;
declare function install<S>(): StoreEnhancer<S>;
declare function loop<S, A extends Action>(
state: S,
cmd: CmdType<A>
): Loop<S, A>;
declare class Cmd {
static readonly dispatch: (action: Action) => void;
static readonly getState: any;
static readonly none: NoneCmd;
static readonly action: <A extends Action>(action: A) => ActionCmd<A>;
static readonly batch: <A extends Action>(cmds: CmdType<A>[]) => BatchCmd<A>;
static readonly sequence: <A extends Action>(cmds: CmdType<A>[]) => SequenceCmd<A>;
static readonly list: <A extends Action>(
cmds: CmdType<A>[],
options?: {
batch?: boolean;
sequence?: boolean;
}
) => ListCmd<A>;
static readonly map: <A extends Action, B extends Action>(
cmd: CmdType<B>,
tagger: (subAction: B) => A,
args?: any[]
) => MapCmd<A>;
static readonly run: <A extends Action>(
f: Function,
options?: {
args?: any[];
failActionCreator?: ActionCreator<A>;
successActionCreator?: ActionCreator<A>;
forceSync?: boolean;
}
) => RunCmd<A>;
}
export type ReducerMapObject<S, A extends Action = AnyAction> = {
[K in keyof S]: LoopReducer<S[K], A>;
}
declare function combineReducers<S, A extends Action = AnyAction>(
reducers: ReducerMapObject<S, A>
): LiftedLoopReducer<S, A>;
declare function mergeChildReducers<S, A extends Action = AnyAction>(
parentResult: S | Loop<S, A>,
action: AnyAction,
childMap: ReducerMapObject<S, A>
): Loop<S, A>;
declare function liftState<S, A extends Action>(
state: S | Loop<S, A>
): Loop<S, A>;
declare function isLoop(test: any): boolean;
declare function getModel<S>(loop: S | Loop<S, AnyAction>): S;
declare function getCmd<A extends Action>(a: any): CmdType<A> | null;