Created
October 4, 2016 20:19
-
-
Save c-jacquin/369c91c6fa75c56bd5adf6568e930fc6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createStore, applyMiddleware, compose } from 'redux'; | |
| import createLogger from 'redux-logger'; | |
| import rootReducer from '../reducers'; | |
| const isDev = process.env.NODE_ENV === 'development'; | |
| function getMiddleware() { | |
| const middleware = []; | |
| return isDev | |
| ? applyMiddleware(...[...middleware, createLogger()]) | |
| : applyMiddleware(...middleware); | |
| } | |
| function getEnhancers() { | |
| const enhancers = []; | |
| return isDev && window.devToolsExtension | |
| ? [...enhancers, window.devToolsExtension()] | |
| : enhancers; | |
| } | |
| function enableHotLoader(store) { | |
| if (isDev && module.hot) { | |
| module.hot.accept('../reducers', () => { | |
| const nextRootReducer = require('../reducers'); | |
| store.replaceReducer(nextRootReducer); | |
| }); | |
| } | |
| } | |
| function configureStore(initialState = {}) { | |
| const store = compose( | |
| getMiddleware(), | |
| ...getEnhancers() | |
| )(createStore)(rootReducer, initialState); | |
| enableHotLoader(store); | |
| return store; | |
| } | |
| export const store = configureStore(); | |
| export default configureStore; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment