-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
Support Hot Reloading of model #168
Comments
Hey @Keyj1n Thanks for raising this. I think I already have most of the work done for this, but need to do a bit more still. I would appreciate it if you could create a minimal example repo for me to test against. 👍 |
I am having an issue with hot reloading right now. All the data in EP models is lost, yet the rest of the store is fine. It's hard to tell if this is related to Easy-Peasy or the convoluted flow currently used. I'm also using a What is the status of hot reloading with EP? Anything you can share would be helpful. One way or another I'll have to find a solution, no matter how hacky! |
This works in I modified a simple Create React App to test it and appears to work. You can modify the state by interacting with the application then make a code change to the model. You will note that the app is updated by state is maintained. 👍 I introduced the following file structure:
src/index.js Firstly, configure the root file responsible for rendering your app to support hot reloading of the App component. import React from "react";
import ReactDOM from "react-dom";
import { StoreProvider } from "easy-peasy";
import App from "./App";
import store from "./store";
const render = Component =>
ReactDOM.render(
<StoreProvider store={store}>
<Component />
</StoreProvider>,
document.getElementById("root")
);
render(App);
if (process.env.NODE_ENV === "development") {
if (module.hot) {
module.hot.accept("./App", () => {
const NextApp = require("./App").default;
render(NextApp);
});
}
} src/store.js Then configure your store to support hot reloading of the model. import { createStore } from "easy-peasy";
import model from "./model";
const store = createStore(model);
if (process.env.NODE_ENV === "development") {
if (module.hot) {
module.hot.accept("./model", () => {
store.reconfigure(model); // 👈 Here is the magic
});
}
}
export default store; |
@allpro @Keyj1n 👆 |
Thanks @ctrlplusb. Will give this a try today. |
Created an example repo and have added to v3 docs |
Tested and confirmed working for me. Thanks @ctrlplusb 👍 |
Thanks for this. |
Vite version if (import.meta.hot) {
import.meta.hot.accept("./model", (newModule) => {
const newModel = newModule.default
store.reconfigure(newModel) // 👈 Here is the magic
})
} |
How can hot reloading be implemented?
I tried it with creating a new store and render the app new but that doesn't work.
Any ideas? Is there a way to create reducers out of the models? Then i can use the standard function replaceReducer of the store.
The text was updated successfully, but these errors were encountered: