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