-
Notifications
You must be signed in to change notification settings - Fork 1
/
configureStore.js
56 lines (45 loc) · 1.69 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
45
46
47
48
49
50
51
52
53
54
55
56
import { applyMiddleware, compose, createStore } from 'redux'
import { routerMiddleware } from 'connected-react-router'
import thunk from 'redux-thunk';
import * as api from './redux/api';
import Container from './util/Container';
import reducers from './redux/index'
import createReducer from './redux/reducerInjector';
const configureStore = (initialState = {}, history) => {
let composeEnhancers = compose;
/** Import api in container so we can access it much easier later */
const container = new Container({
api
});
// If Redux Dev Tools and Saga Dev Tools Extensions are installed, enable them
if (process.env.NODE_ENV !== 'production' && typeof window === 'object') {
/* eslint-disable no-underscore-dangle */
if (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__)
composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({});
}
// Add middlewares to store
const middlewares = [
thunk.withExtraArgument(container),
routerMiddleware(history)
];
const enhancers = [applyMiddleware(...middlewares)];
const injectedReducers = {
...reducers,
// Here we can inject reducers we want to share between projects
};
const store = createStore(
createReducer(injectedReducers),
initialState,
composeEnhancers(...enhancers),
);
// Extensions
store.injectedReducers = injectedReducers; // Reducer registry
// Make reducers hot reloadable
if (module.hot) {
module.hot.accept('./redux/reducerInjector', () => {
store.replaceReducer(createReducer(store.injectedReducers));
});
}
return store;
};
export default configureStore