-
Notifications
You must be signed in to change notification settings - Fork 11
/
store.tsx
89 lines (81 loc) · 2.82 KB
/
store.tsx
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
import * as About from './About';
import * as Automaton from './Automaton';
import * as ContextMenu from './ContextMenu';
import * as CurveEditor from './CurveEditor';
import * as FxSpawner from './FxSpawner';
import * as Header from './Header';
import * as History from './History';
import * as Settings from './Settings';
import * as TextPrompt from './TextPrompt';
import * as Timeline from './Timeline';
import * as Toasty from './Toasty';
import * as Workspace from './Workspace';
import { Dispatch, Store, combineReducers, createStore as createReduxStore } from 'redux';
import { shallowEqual, useDispatch as useReduxDispatch, useSelector as useReduxSelector, useStore as useReduxStore } from 'react-redux';
// == state ========================================================================================
export interface State {
about: About.State;
automaton: Automaton.State;
contextMenu: ContextMenu.State;
curveEditor: CurveEditor.State;
fxSpawner: FxSpawner.State;
header: Header.State;
history: History.State;
settings: Settings.State;
textPrompt: TextPrompt.State;
timeline: Timeline.State;
toasty: Toasty.State;
workspace: Workspace.State;
}
// == action =======================================================================================
export type Action = (
About.Action |
Automaton.Action |
ContextMenu.Action |
CurveEditor.Action |
FxSpawner.Action |
Header.Action |
History.Action |
Settings.Action |
TextPrompt.Action |
Timeline.Action |
Toasty.Action |
Workspace.Action |
{ type: 'Reset' }
);
// == reducer ======================================================================================
const reducer = combineReducers<State>( {
about: About.reducer,
automaton: Automaton.reducer,
contextMenu: ContextMenu.reducer,
curveEditor: CurveEditor.reducer,
fxSpawner: FxSpawner.reducer,
header: Header.reducer,
history: History.reducer,
settings: Settings.reducer,
textPrompt: TextPrompt.reducer,
timeline: Timeline.reducer,
toasty: Toasty.reducer,
workspace: Workspace.reducer
} );
// == store ========================================================================================
export function createStore(): Store<State, Action> {
let devtools: any;
if ( typeof window !== 'undefined' ) { // vs. node.js
devtools = window && ( window as any ).__REDUX_DEVTOOLS_EXTENSION__;
}
return createReduxStore(
reducer,
devtools && devtools()
);
}
// == utils ========================================================================================
export function useSelector<T>( selector: ( state: State ) => T ): T {
return useReduxSelector( selector, shallowEqual );
}
export function useDispatch(): Dispatch<Action> {
return useReduxDispatch<Dispatch<Action>>();
}
export function useStore(): Store<State, Action> {
return useReduxStore();
}