-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.d.ts
84 lines (71 loc) · 2.11 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
export interface Module {
state?: Record<string, any>;
reducers?: Record<string, any>;
effects?: Record<string, any>;
}
export interface Bootstrap {
<Modules>(modules: Modules): {
useModule: UseModule<Modules>;
dispatch: InnerDispatch<Modules>;
};
DISPATCH_TYPE: string;
addPlugin: (plugin: any) => void;
}
export type NameSpaceDeclare<Modules> = keyof Modules | (keyof Modules)[];
export type UseModule<Modules extends Record<string, Module>> = <
NameSpace extends NameSpaceDeclare<Modules>
>(
namespace: NameSpace,
) => NameSpace extends keyof Modules
? { [key in NameSpace]: Modules[key]['state'] }
: { [key in NameSpace[number]]: Modules[key]['state'] };
export type RootEffects<Modules> = {
[key in keyof Modules]: Modules[key]['effects'] extends undefined
? Record<string, any>
: {
[fnKey in keyof Modules[key]['effects']]: (
payload?: Parameters<Modules[key]['effects'][fnKey]>[0]['payload'],
) => any;
};
};
export type RootReducers<Modules> = {
[key in keyof Modules]: Modules[key]['reducers'] extends undefined
? Record<string, any>
: {
[fnKey in keyof Modules[key]['reducers']]: (
payload?: Parameters<Modules[key]['reducers'][fnKey]>[0]['payload'],
) => any;
};
};
export type Dispatch = (
namespace: string,
payload?: Record<string, any>,
) => any;
export type InnerDispatch<Modules> = Dispatch &
RootEffects<Modules> &
RootReducers<Modules>;
export type MixinModule<C, M> = {
[key in keyof M]: {
state: M[key]['state'] & C['state'];
reducers: M[key]['reducers'] & C['reducers'];
effects: M[key]['effects'] & C['effects'];
};
};
export type EffectProps<T, S = any, R = Record<string, any>> = {
payload: T;
state: S;
rootState: R;
dispatch?: any;
};
export type ReducerProps<T, S = any, R = Record<string, any>> = {
payload: T;
state: S;
rootState: R;
};
export type Plugin = (modules: any, on: any) => void;
export const mixin: <C extends Module, M extends Record<string, Module>>(
common: C,
modules: M,
) => MixinModule<C, M>;
const bootstrap: Bootstrap;
export default bootstrap;