New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discussion: hot reload by overriding exported members? #22
Comments
@peteruithoven Exactly what i was thinking when I saw this code: export default function configureStore(initialState) {
const store = createStore(rootReducer, initialState)
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers', () => {
const nextReducer = require('../reducers')
store.replaceReducer(nextReducer)
})
}
return store
} In the redux library, there is an example todoMVC app that has this code. |
@veggiemonk I am using jspm-hot-reloader mainly with observables. Yes, I am the devil @gaearon speaks about every time he mentions how bad one mutating state is. |
I wasn't suggesting making a exception for Redux, but I was asking whether the hot reloader could hot reload modules with stateless / pure functions without reloading all the modules that use that module. |
same question here. |
I've been thinking about this and read through the hot reloader code. I can't think of a way to override the references to exports of an old module a module has, without having access to that class. But maybe, just like __unload is called, a |
@veggiemonk, would that enable that to do what you want? |
@peteruithoven Thank you very much, I will give it try and the idea is quite neat... Do you have any idea on:
The goal here would be to modify the code of the app as little as possible in order to keep this a dev feature, meaning configurable so no extra dev code is shipped to production I would love this to be just a parameter object that could be pass from |
I found that there are also project that allow this to happen at the application code level (not as good as dev-server level) With a working example by @mijime But that is another, less preferable, approach to letting the server know how to save and inject state from old modules to new ones. |
I've made a basic example and a probably flawed pull request: #23 |
@peteruithoven so this was merged, I am closing this discussion for now. |
Like capaj explains in #17 (comment) the hot reloader currently also reloads all modules that use a module that is changed.
But is this really necessary? Could we for example override all exported members (functions / classes) with the members of the new version?
One thing that's probably tricky (if not impossible) are primary variables (numbers, strings etc).
Maybe we could implement "proxy's", like Dan Abramov explains in his talk: https://youtu.be/xsSnOQynTHs
This feature should improve editing stateless functions, like Redux reducers. Since in Redux reducers are used to create the store (state), because they define the initial state of their part, they can't be reloaded without also reloading the state.
The text was updated successfully, but these errors were encountered: