Files: cdd217083b6f75828df3910f914dc5d9bf46437f / app / store.js
1368 bytesRaw
1 | import { createStore, compose, applyMiddleware } from 'redux' |
2 | import thunk from 'redux-thunk' |
3 | import { syncHistory } from 'redux-simple-router' |
4 | |
5 | import reducer from 'app/reducer' |
6 | |
7 | if (process.env.NODE_ENV === 'development') { |
8 | var logger = require('redux-logger') |
9 | var DevTools = require('app/util/dev-tools').default |
10 | } |
11 | |
12 | let storeEnhancers = [] |
13 | let middleware = [] |
14 | |
15 | middleware.push(thunk) |
16 | |
17 | if (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 | |
34 | export 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