-
Notifications
You must be signed in to change notification settings - Fork 330
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
Reflux stores don't play nice with webpack Hot Module Replacement #385
Comments
I've peeked into the webpack docs, but still haven't really gotten any insights on how to do it easily with reflux as I'm not using webpack in any project. Any suggestions on how to proceed with this? |
Um... I doubt if it is Reflux issue at all. If you are using |
We have been using reflux on a few projects and just started using webpack hot reloading. In order to make reflux stores play nicely with hot module reloading the following needs to happen on module.hot
During a hot swap, you have the opportunity to handle these kinds of cases via code like:
I need to do further research into the webpack hot reload api to understand the specific implementation of accept/dispose for these purposes. I'm also not sure if this is possible in a generic implementation with the current reflux API unless there is a specific way that Store state is stored. For example we use Store.data to store the state but this is not a requirement of reflux. It should also be possible to provide a generic webpack loader which can be applied to stores which automatically adds this hot reloading code to copy old state and remove old subscriptions during a hot reload. References |
If some simple boilerplate code or a reflux extension can achieve this, I would personally prefer that over baking it into refluxjs or reflux-core itself. |
For my purposes I've added some code to a library I'm building. I'm not sure if it will be relevant to vanilla-reflux, but it's doing this - accept module at the store itself -> listen to old store from the new modified store. you can take a look. |
Btw if you just add storeKeys to your components, HMR works perfectly. This also happens to be a really good pattern to follow in my opinion Spez: You also need to have default values in your state declaration corresponding with the storeKeys that will overwrite them. This is annoying but also not a terrible pattern |
If have simple application using Reflux and everything works properly. I'm using webpack to build and run everything with HMR support. The react components get hot swapped properly and also the Actions and Stores get hot swapped. The only problem is the 'old' Store is still active and still reacting to the Actions. So every compile that changes something in a Store, you end up with another version of the Store.
Is there something that can be done to fix this?
The text was updated successfully, but these errors were encountered: