forked from ZJU-CC98/Forum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Store.tsx
51 lines (43 loc) · 1.57 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
import createHistory from 'history/createBrowserHistory';
import { routerMiddleware, routerReducer as router, RouterState } from 'react-router-redux';
import { applyMiddleware, combineReducers, compose, createStore, Dispatch } from 'redux';
import thunk from 'redux-thunk';
import * as ThunkActions from './AsyncActions';
import * as UserActions from './Actions/UserCenter';
import * as ErrorActions from './Actions/Error';
import * as MessageActions from './Actions/Message';
import error, { ErrorStore } from './Reducers/Error';
import userInfo, { UserInfoStore } from './Reducers/UserInfo';
import message, { MessageInfo } from './Reducers/Message';
/**
* 全局store的类型定义
*/
export interface RootState {
error: ErrorStore;
userInfo: UserInfoStore;
message: MessageInfo;
router: RouterState;
}
export const Actions = { ...UserActions, ...ErrorActions, ...MessageActions };
type actionTypes = keyof typeof Actions
type thunkActionTypes = keyof typeof ThunkActions;
/**
* 全部Action的类型定义
*/
export type RootAction = ReturnType<typeof Actions[actionTypes]>;
export type RootThunkAction = ReturnType<typeof ThunkActions[thunkActionTypes]>;
/**
* 合并reducer
*/
const reducer = combineReducers<RootState>({
error,
router,
userInfo,
message,
});
export const history = createHistory();
/**
* 连接到redux开发者工具
*/
const composeEnhancers: typeof compose = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
export default createStore(reducer, composeEnhancers(applyMiddleware(thunk, routerMiddleware(history))));