|
1 | | -import { compose, createStore, applyMiddleware } from 'redux'; |
2 | | -import thunk from 'redux-thunk'; |
3 | | -import rootReducer from '../reducers'; |
4 | | -import persistState from 'redux-localstorage'; |
5 | | -import { syncHistory } from 'react-router-redux'; |
6 | | - |
7 | | -export default function configureStore(initialState, options = {}) { |
8 | | - const opts = Object.assign({}, { |
9 | | - history: null, |
10 | | - dispatchRouteChanges: false |
11 | | - }, options); |
12 | | - |
13 | | - |
14 | | - /* localStorage Persisted States |
15 | | - * Set up persisted state properties via localStorage. They should be added |
16 | | - * by their property name of the piece of state you want to persist, e.g: |
17 | | - * const persistedStates = ['session', 'order']; |
18 | | - */ |
19 | | - const persistedStates = []; |
20 | | - |
21 | | - /* Middleware |
22 | | - * Configure this array with the middleware that you want included. thunk |
23 | | - * is included by default, and react-router-redux's syncHistory is also |
24 | | - * applied if an `options.history` object was passed to configureStore. |
25 | | - */ |
26 | | - const middleware = [ |
27 | | - // add more middlware here |
28 | | - thunk |
29 | | - ].concat( |
30 | | - opts.history ? [syncHistory(opts.history)] : [] |
31 | | - ); |
32 | | - |
33 | | - // Create an a composed method which enhances redux's createStore with |
34 | | - // additional functionality |
35 | | - let enhancers = [ |
36 | | - // Universal enhancers (both server and client-side) |
37 | | - applyMiddleware.apply(this, middleware) |
38 | | - |
39 | | - ].concat(isBrowser() ? [ |
40 | | - // Add browser/client-side only enhancers here |
41 | | - // e.g. localStorage, geolocation, etc. |
42 | | - persistState(persistedStates) |
43 | | - |
44 | | - ] : [ |
45 | | - // Add server-side only enhancers here |
46 | | - |
47 | | - ]); |
48 | | - |
49 | | - let enhanced = compose.apply(this, enhancers); |
50 | | - |
51 | | - // create store with enhancers, middleware, reducers, and initialState |
52 | | - const store = enhanced(createStore)(rootReducer, initialState); |
53 | | - |
54 | | - if (module.hot) { |
55 | | - // Enable Webpack hot module replacement for reducers |
56 | | - module.hot.accept('../reducers', () => { |
57 | | - const nextRootReducer = require('../reducers').default; |
58 | | - store.replaceReducer(nextRootReducer); |
59 | | - }); |
60 | | - } |
61 | | - |
62 | | - return store; |
63 | | -} |
64 | | - |
65 | | -function isBrowser() { |
66 | | - return (typeof window !== 'undefined' && typeof window.document !== 'undefined'); |
| 1 | +if (process.env.NODE_ENV === 'production') { |
| 2 | + module.exports = require('./store.prod'); |
| 3 | +} else { |
| 4 | + module.exports = require('./store.dev'); |
67 | 5 | } |
0 commit comments