Files: 151a4f083fcf9352422148bd94eebc170209c940 / app / store.js
1163 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 | if (module.browser) { |
23 | storeEnhancers.push( |
24 | applyMiddleware(logger()) |
25 | ) |
26 | } |
27 | |
28 | storeEnhancers.push(DevTools.instrument()) |
29 | |
30 | if (module.browser) { |
31 | let { persistState } = require('redux-devtools') |
32 | storeEnhancers.push(persistState( |
33 | window.location.href.match( |
34 | /[?&]debug_session=([^&]+)\b/ |
35 | ) |
36 | )) |
37 | } |
38 | } |
39 | |
40 | const createEnhancedStore = compose( |
41 | ...storeEnhancers |
42 | )(createStore) |
43 | |
44 | export default function finalCreateStore(initialState) { |
45 | const store = createEnhancedStore(reducer, initialState) |
46 | |
47 | if (module.hot) { |
48 | module.hot.accept('app/reducer', () => { |
49 | store.replaceReducer(require('app/reducer')) |
50 | }) |
51 | } |
52 | |
53 | return store |
54 | } |
55 |
Built with git-ssb-web