-
Notifications
You must be signed in to change notification settings - Fork 46
/
configureStore.js
executable file
·36 lines (30 loc) · 1.22 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
import { createStore, applyMiddleware, compose, combineReducers } from 'redux'
import { composeWithDevTools } from 'redux-devtools-extension/logOnlyInProduction'
import { connectRoutes } from 'redux-first-router'
import routesMap from './routesMap'
import options from './options'
import * as reducers from './reducers'
import * as actionCreators from './actions'
export default (history, preLoadedState) => {
const { reducer, middleware, enhancer, thunk } = connectRoutes(
history,
routesMap,
options
)
const rootReducer = combineReducers({ ...reducers, location: reducer })
const middlewares = applyMiddleware(middleware)
const enhancers = composeEnhancers(enhancer, middlewares)
const store = createStore(rootReducer, preLoadedState, enhancers)
if (module.hot && process.env.NODE_ENV === 'development') {
module.hot.accept('./reducers/index', () => {
const reducers = require('./reducers/index')
const rootReducer = combineReducers({ ...reducers, location: reducer })
store.replaceReducer(rootReducer)
})
}
return { store, thunk }
}
const composeEnhancers = (...args) =>
typeof window !== 'undefined'
? composeWithDevTools({ actionCreators })(...args)
: compose(...args)