Skip to content

Instantly share code, notes, and snippets.

@TheDutchCoder
Last active January 5, 2016 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheDutchCoder/3914fef3a6989851acff to your computer and use it in GitHub Desktop.
Save TheDutchCoder/3914fef3a6989851acff to your computer and use it in GitHub Desktop.
Hot Reloading reducers
// 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