-
Notifications
You must be signed in to change notification settings - Fork 65
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
Consider adding rememberRetainedSaveable variant #722
Comments
What would an example of one of these look like? I'm inclined to lean toward what you mentioned at the end – decomposing your state and persisting them at whatever their correct granularity is. |
@alexvanyo is this covered by #888 or still a different proposal? |
I think this is still a different proposal than #888. The use case would be an object that would ideally be retained, but for the event of process death, some parts should be saved and restored from instance state to be used instead of the original initialization call. Maybe an example would be an object with a couple of ids that should survive process death, but the object also has some larger bits of data that would be good to retain? The flow for
The flow for
I think a combined flow for
The retained value, if available, takes first precedence, but if the retained value isn't available, it falls back to whatever was stored in instance state first, before finally falling back to re-initializing the object entirely. |
Sounds good to me, PR would be welcome. I worry a little about the API surface area but can't think offhand of a solution that could make this more hierarchical and I suspect automatic isn't something we want here. @stagg and @chrisbanes may have better ideas |
Yeah, I have the same worries about the API surface. I personally think this is better handled at the caller level, by using both |
I've been looking a little more into this, and I think it's mechanically mostly doable but two issues/considerations arise
|
I think if it's |
My first thought would that rememberRetained with saveable saving on process death makes the most sense to me, as it uses the key benefits of both features. |
With the exploration in #1305, I think
I think a |
Think it's this, where saveable is an extension of retained. Requiring anyone wanting to opt-in to explicitly set the saver as @alexvanyo suggests. No default auto-saving option. |
Could we make it work that way in code? Basically have rememberRetained call through with that? |
Or just add a |
yeah that's what I was thinking too 👀 |
Updated #1305 to combine the backing implementation, and to see what it looks like to add the I think I initially prefer to have explictly separate |
Shipped in 0.21.0 |
It might be possible to have
rememberRetainedSaveable
, a combination ofrememberSaveable
andrememberRetained
, for preserving a state holder which won't be recreated for configuration changes, but will still save and restore instance state through process death.The use case could be for a complex state holder that has both unbounded data that should be kept in memory through configuration changes, and some simpler data that should be saved and restored through process death.
The backing implementation could use
SavedStateHandle
to hook into the saved instance state.Alternatively, this could intentionally not be provided as an API, with the expectation that a state holder like the one described above should be split into two parts: the part that is retained in memory, and the part that is preserved through saved instance state.
The text was updated successfully, but these errors were encountered: