Last active
January 5, 2016 20:22
-
-
Save TheDutchCoder/3914fef3a6989851acff to your computer and use it in GitHub Desktop.
Hot Reloading reducers
This file contains 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
// This is how I setup my store, but I'm unsure how to enable Hot Reloading for reducers. | |
// I feel it might have something to do with the middleware. | |
// | |
// Setup the middleware and create the store. | |
const loggerMiddleware = createLogger() | |
let middleWare = [thunkMiddleware, loggerMiddleware] | |
const finalCreateStore = compose( | |
applyMiddleware(...middleWare), | |
DevTools.instrument() | |
)(createStore) | |
const store = finalCreateStore(mainApp) | |
const history = createHistory() | |
syncReduxAndRouter(history, store) | |
// In most examples I've found, the following code would be used in some form: | |
// Setup the middleware and create the store. | |
const loggerMiddleware = createLogger() | |
let middleWare = [thunkMiddleware, loggerMiddleware] | |
const finalCreateStore = compose( | |
applyMiddleware(...middleWare), | |
DevTools.instrument() | |
)(createStore) | |
const store = finalCreateStore(mainApp) | |
const history = createHistory() | |
// Here's where HMR would be enabled for reducers, however this throws an error when the reducer is changed. | |
if (module.hot) { | |
module.hot.accept('./reducers', () => { | |
const nextRootReducer = require('./reducers/index') | |
store.replaceReducer(nextRootReducer) | |
}) | |
} | |
syncReduxAndRouter(history, store) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment