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
Proposal: Preserve ViewModel state on live-reloads #1151
Comments
maybe we should simply make a guide for serialize and hydrate viewModel to localstorage? |
@frank-dspeed do you mean how to do it manually? That's not a terrible idea. |
Two thoughts on this:
|
My comments on time-travel debugging might be related: canjs/canjs#4529 |
@chasenlehara it's related, but SSR data caching is far more simple as requests are more or less stateless. It's so simple that it's very unlikely the same approach can be used. The hard part is how to deal with side effects. Say I wrote a component like: ViewModel: {
todos: "any",
connectedCallback(){
Todo.getList({}).then( (todos) => {
this.todos = todos;
})
}
} Do we serialize I think we should identify what sorts of state we really want to "keep" and which we do not. For example, a tab-like component:
What it seems we would really need is just a way to save the last value to localStorage and use it as the default value:
The problem here is what to do if there are multiple |
Just a sidebar, as it relates to live-reload localStorage is not needed as the browser doesn't actually refresh. We can just save the state in a Map of some kind in memory. |
@justinbmeyer in my new proposal that is linked to this issue i will prepare a little util helper function that will simply allow to store values on change and listen for values also it will publish values on load you will to add that explicit for the values that need perserve of state
something like that i am not finished with the final api but i think you get the concept |
the guide for this should maybe show simply getter setter logic and value logic for preservingState some where |
One problem folks have today is that when live-reload occurs it removes all state that's not in the URL. We could possibly improve upon this by saving ViewModels (serializing them perhaps) and restoring them later. Will take more thought to figure out but I wanted to get this proposal out there.
The text was updated successfully, but these errors were encountered: