fabiospampinato / overstated

React state management library that's delightful to use, without sacrificing performance or scalability.
MIT License
83 stars 6 forks source link

Hot Module Replacement #6

Open Saltallica opened 5 years ago

Saltallica commented 5 years ago

First off - thanks for this awesome library - I was able to get up and running in minutes. I've used Redux extensively and the Overstated/Unstated pattern is soooo much easier to work with - so thank you! :smile:

My particular project is using create-react-app and hot module reloading via react-hot-loader. Sometimes as I modify components they reload/rerender, but my store values are empty - is there anyway I can ensure that as my components are reloaded that my stores stay as is?

Thanks!

fabiospampinato commented 5 years ago

I'm glad you're enjoying it too!

There's actually a todo about this already, and I had developed a little plugin for unstated that enabled hmr support.

But this feature turned out to be trickier to implement than expected, because you can't just naively restore the previous states (that's what my plugin was doing), because for instance if you decide to change the structure of your state then replacing it with the old one will break things.

I'm not sure what's the proper way of implementing this yet 🤔

fabiospampinato commented 5 years ago

Maybe we should just restore the state objects, and if you changed their structure or something you'll be required to reload the app manually 🤔