-
-
Notifications
You must be signed in to change notification settings - Fork 190
/
external-type-defs.ts
63 lines (50 loc) · 1.13 KB
/
external-type-defs.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
import {
action,
Action,
computed,
Computed,
thunk,
Thunk,
effectOn,
EffectOn,
} from 'easy-peasy';
type MyModelEffectOn = EffectOn<MyModel>;
type MyModelAction<TPayload = void> = Action<MyModel, TPayload>;
type MyModelComputed<TResult> = Computed<MyModel, TResult>;
type MyModelThunk<TPayload = undefined, TResult = any> = Thunk<
MyModel,
TPayload,
any,
{},
Promise<TResult>
>;
type MyState = {
value: string;
};
type MyThunkPayload = { data: string };
interface MyModel {
myState: MyState;
myComputed: MyModelComputed<number>;
setMyState: MyModelAction<string>;
myThunk: MyModelThunk<MyThunkPayload, boolean>;
myEffectOn: MyModelEffectOn;
}
const myModel: MyModel = {
myState: {
value: 'initial',
},
setMyState: action((state, payload) => {
state.myState = {
value: payload,
};
}),
myComputed: computed((state) => state.myState.value.length),
myThunk: thunk(async (actions, payload) => {
actions.setMyState('a');
// some kind of await
return true;
}),
myEffectOn: effectOn([(state) => state.myState.value], (actions, change) => {
// do something
}),
};