-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigureStore.js
44 lines (36 loc) · 1.24 KB
/
configureStore.js
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
import { createStore, applyMiddleware, compose } from 'redux';
import { fromJS } from 'immutable';
import { routerMiddleware } from 'react-router-redux';
import { conventionalReduxMiddleware, setRecreateReducerFunction, registerInteractors } from 'conventional-redux'
import RouteCounterInteractor from './RouteCounterInteractor';
import createReducer from './reducers';
import logger from 'utils/reduxLogger'
export default function configureStore(initialState = {}, history) {
const middlewares = [
routerMiddleware(history),
conventionalReduxMiddleware,
logger
];
const enhancers = [
applyMiddleware(...middlewares),
];
const store = createStore(
createReducer(),
fromJS(initialState),
compose(...enhancers)
);
// only for debug purpose!
window.store = store;
// conventional redux config - registering static interactors
registerInteractors({
route_counter: new RouteCounterInteractor()
});
// conventional redux config - function to recreate reducer (using to replace dynamic interactors)
setRecreateReducerFunction(() => store.replaceReducer(createReducer()));
if (module.hot) {
module.hot.accept('./reducers', () => {
store.replaceReducer(createReducer());
});
}
return store;
}