-
Notifications
You must be signed in to change notification settings - Fork 57
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
Persistence of View/Model data #25
Comments
How about this for cx.build?
That way, we call new_builder if the data is being constructed for the first time and then insert the return value into the state, and we call update_builder with a mutable reference to the value already in the state if one exists. |
I do like this as it seems more consistent with the current API. But I think most of the time the update closure will be empty. |
Yes, I believe we have answered this pretty conclusively in the direction of "models and views should never persist through rebuilds". |
Currently when a view is built using
Self{ }.build2(cx, |cx|{ })
the closure is run every time but the view is not added to the context if it already exists. This means that any changes to fields inSelf { }
are not updated when the view is rebuilt.This isn't necessarily a problem because any data that did need to be updated could live in a model which is updated when rebuilt. So when you have some data
AppData{ }.build(cx)
, this is updated with new values every time it is called, so calling it inside a binding updates that data every time the binding is rebuilt.This whole system presents a few problems. The first is that there are two different places data can live and two different behaviours that can happen when rebuilt:
Data inside of views is local to the view wheras data inside of models can be shared accross multiple views.
The second problem is that even when data is updated there is no easy access to the previous version of the data without having to get a view/model from context and downcasting it to the right type. This becomes a problem if you want to conditionally update a view/model. A further problem is that sometimes it's necessary to persist model data, resulting in an ugly
if cx.data::<AppData>().is_none()
check.I think what is needed is an explicit way for the user to determine if the view/model data should be updated or not if there is already a version in context. I'm not sure of the exact systax yet, but perhaps something like:
This isn't ideal because it shoudn't be possible to not create a new instance when there isn't a previous one but it's a start. I'm very much open to suggestions.
The text was updated successfully, but these errors were encountered: