-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathstore.ts
40 lines (34 loc) · 1.17 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
import { createStore, applyMiddleware, compose } from 'redux';
import { createEpicMiddleware } from 'redux-observable';
import { routerMiddleware as createRouterMiddleware } from 'react-router-redux';
import { createBrowserHistory } from 'history';
import { rootReducer, RootState } from 'Features/root-reducer';
import { rootEpic } from 'Features/root-epic';
const composeEnhancers = (
process.env.NODE_ENV === 'development' &&
window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
) || compose;
export const epicMiddleware = createEpicMiddleware(rootEpic);
export const browserHistory = createBrowserHistory();
export const routerMiddleware = createRouterMiddleware(browserHistory);
function configureStore(initialState?: RootState) {
// configure middlewares
const middlewares = [
epicMiddleware,
routerMiddleware,
];
// compose enhancers
const enhancer = composeEnhancers(
applyMiddleware(...middlewares)
);
// create store
return createStore(
rootReducer,
initialState!,
enhancer
);
}
// pass an optional param to rehydrate state on app start
export const store = configureStore();
// export store singleton instance
export default store;