Files: 51f5f8f504793351faa020ae6f5b8826c175aceb / app / store.js
1090 bytesRaw
1 | const { createStore, compose, applyMiddleware } = require('redux') |
2 | const thunk = require('redux-thunk') |
3 | const { createHistory } = require('history') |
4 | |
5 | const reducer = require('app/reducer') |
6 | |
7 | let storeEnhancers = [] |
8 | let middleware = [] |
9 | |
10 | middleware.push(thunk) |
11 | |
12 | storeEnhancers.push( |
13 | applyMiddleware(...middleware) |
14 | ) |
15 | |
16 | if (process.env.NODE_ENV === 'development') { |
17 | let logger = require('redux-logger') |
18 | storeEnhancers.push( |
19 | applyMiddleware(logger()) |
20 | ) |
21 | |
22 | let DevTools = require('app/dev/tools') |
23 | storeEnhancers.push(DevTools.instrument()) |
24 | |
25 | if (module.browser) { |
26 | let { persistState } = require('redux-devtools') |
27 | storeEnhancers.push(persistState( |
28 | window.location.href.match( |
29 | /[?&]debug_session=([^&]+)\b/ |
30 | ) |
31 | )) |
32 | } |
33 | } |
34 | |
35 | const createEnhancedStore = compose( |
36 | ...storeEnhancers |
37 | )(createStore) |
38 | |
39 | function finalCreateStore(initialState) { |
40 | |
41 | if (module.hot) { |
42 | module.hot.accept('app/reducer', () => { |
43 | store.replaceReducer(require('app/reducer')) |
44 | }) |
45 | } |
46 | |
47 | return createEnhancedStore(reducer, initialState) |
48 | } |
49 | |
50 | module.exports = finalCreateStore |
51 |
Built with git-ssb-web