-
Notifications
You must be signed in to change notification settings - Fork 0
/
configureStore.js
53 lines (50 loc) · 1.49 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
import { combineReducers, applyMiddleware, createStore, compose } from 'redux'
import { createFalcorMiddleware, falcorReducer } from 'redux-falcor'
import falcor from 'falcor'
import { reduxReactRouter, routerStateReducer } from 'redux-router'
import { createHistory } from 'history'
import promiseMiddleware from 'redux-promise'
import { warningMiddleware } from '../middleware'
import * as reducers from '../reducer'
import routes from '../route'
const reducer = combineReducers({
...reducers,
entities: falcorReducer,
router: routerStateReducer,
})
const model = new falcor.Model({
source: new falcor.HttpDataSource('/model.json'),
})
let finalCreateStore = null
if (process.env.NODE_ENV === 'development') {
const devTool = require('../dev-tool')
const { persistState } = require('redux-devtools')
finalCreateStore = compose(
applyMiddleware(promiseMiddleware, createFalcorMiddleware(model),
warningMiddleware),
reduxReactRouter({
routes,
createHistory,
}),
devTool.instrument(),
persistState(window.location.href.match(
/[?&]debug_session=([^&]+)\b/)),
)(createStore)
} else {
finalCreateStore = compose(
applyMiddleware(promiseMiddleware, createFalcorMiddleware(model)),
reduxReactRouter({
routes,
createHistory,
}),
)(createStore)
}
export default function configureStore(initialState) {
const store = finalCreateStore(reducer, initialState)
if (module.hot) {
module.hot.accept('../reducer', () =>
store.replaceReducer(require('../reducer'))
)
}
return store
}