git ssb

1+

dinoworm ๐Ÿ› / catstack



Tree: cdd217083b6f75828df3910f914dc5d9bf46437f

Files: cdd217083b6f75828df3910f914dc5d9bf46437f / app / store.js

1368 bytesRaw
1import { createStore, compose, applyMiddleware } from 'redux'
2import thunk from 'redux-thunk'
3import { syncHistory } from 'redux-simple-router'
4
5import reducer from 'app/reducer'
6
7if (process.env.NODE_ENV === 'development') {
8 var logger = require('redux-logger')
9 var DevTools = require('app/util/dev-tools').default
10}
11
12let storeEnhancers = []
13let middleware = []
14
15middleware.push(thunk)
16
17if (process.env.NODE_ENV === 'development') {
18 if (process.browser) {
19 middleware.push(logger())
20 }
21
22 storeEnhancers.push(DevTools.instrument())
23
24 if (module.browser) {
25 let { persistState } = require('redux-devtools')
26 storeEnhancers.push(persistState(
27 window.location.href.match(
28 /[?&]debug_session=([^&]+)\b/
29 )
30 ))
31 }
32}
33
34export default function finalCreateStore(initialState, history) {
35 const historyMiddleware = syncHistory(history)
36
37 const finalMiddleware = middleware.concat([
38 historyMiddleware
39 ])
40
41 const createEnhancedStore = compose(
42 applyMiddleware(...finalMiddleware),
43 ...storeEnhancers
44 )(createStore)
45
46 const store = createEnhancedStore(reducer, initialState)
47
48 if (process.env.NODE_ENV === 'development') {
49 historyMiddleware.listenForReplays(store)
50 }
51
52 if (module.hot) {
53 module.hot.accept('app/reducer', () => {
54 store.replaceReducer(require('app/reducer'))
55 })
56 }
57
58 return store
59}
60

Built with git-ssb-web