-
-
Notifications
You must be signed in to change notification settings - Fork 190
/
store.ts
84 lines (68 loc) · 1.76 KB
/
store.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
import {
Action,
action,
createStore,
ReduxAction,
Thunk,
thunk,
} from 'easy-peasy';
import { Reducer } from 'redux';
interface Model {
count: number;
doActionVoid: Action<Model>;
doAction: Action<Model, boolean>;
doThunk: Thunk<Model, number>;
}
const model: Model = {
count: 0,
doActionVoid: action(() => {}),
doAction: action(() => {}),
doThunk: thunk(() => {}),
};
interface PersistPartial {
persist: string;
}
function persistReducer<S, A extends ReduxAction>(
baseReducer: Reducer<S, A>,
): Reducer<S & PersistPartial, A> {
return (baseReducer as unknown) as Reducer<S & PersistPartial, A>;
}
const store = createStore(model, {
reducerEnhancer: (reducer) => persistReducer(reducer),
});
const configuredStore = createStore(model, {
disableImmer: false,
devTools: false,
initialState: { foo: 'bar' },
injections: { foo: 'bar' },
mockActions: true,
name: 'bob',
version: 1,
reducerEnhancer: (reducer) => reducer,
});
store.getActions().doActionVoid();
store.getActions().doAction(true);
store.dispatch.doAction(true);
// @ts-expect-error
store.getActions().doAction(1);
// @ts-expect-error
store.dispatch.doAction(1);
store.getActions().doThunk(1);
store.dispatch.doThunk(1);
// @ts-expect-error
store.getActions().doThunk(true);
// @ts-expect-error
store.dispatch.doThunk(true);
store.getMockedActions()[0].type;
store.clearMockedActions();
store.persist.clear().then(() => undefined);
store.persist.flush().then(() => undefined);
store.persist.resolveRehydration().then(() => undefined);
// @ts-expect-error
store.addModel();
// @ts-expect-error
store.addModel('bar');
// @ts-expect-error
store.addModel('bar', true);
const addModelResult = store.addModel('foo', {});
addModelResult.resolveRehydration().then(() => undefined);