If anyone’s been curious how something like `mutab...
# compose
z
If anyone’s been curious how something like
mutableStateOf
actually works at the lowest level, you might find this interesting.
👍 5
💯 4
👍🏼 3
K 3
K 3
t
Do you have some part that talk about the mixing of remember and derivedStateOf?
z
I don't actually discuss derivedStateOf at all here, but that would be a good follow up.
What sort of information specifically were you looking for?
t
Well I was just caught on a subtle thing with a remember / derivedState and a state + something that in the end was not a state so did not recalculate.
Copy code
val orientation = LocalConfiguration.current.orientation
So the obvious fix was to remember(orientation) but maybe some more docs about how to detect what is seen as a state of not in that case to better avoid such mistakes would be nice.
l
This reminds me what I've made; I wanted to make some persistent data work with snapshot system. It works well for me, but I cannot know if it has any problem. It 'synchronizes' data if it is applied globally. Otherwise it is left to be merely local value in current snapshot. I used this to make PreferenceState snapshot compatible. (though I could used Flow or anything)
z
@Tolriq IIUC that just sounds like something that should have been backed by a snapshot state wasn't? I don't know what to tell you there - the state system doesn't participate in the type system so the only way to know if something is snapshot aware is to look at the code or trust trust the docs. Presumably if you had a static analyzer doing whole-program data flow analysis you could check, but nothing in compose does that at this point. I'm general though, nothing coming from the platform (such as eg the
Configuration
class) will be snapshot aware.
t
Yes it was a mistake, but not an easy one to find, derivedStateOf is always wrapped in remember {} in all examples. XXXX.current does sounds like reading a state, Well to resume there's not enough emphasis about state only = snapshot state and the impact of the remember wrapping when reading other things in the derivedStateOf. Having another high profile writer talking about it could help others too.
z
Fair enough. Could you file a bug? I’ll make sure it gets routed to the right people to update the docs.
t
Yes I can, can you point me the right category ?
z
just put it in Jetpack Compose and i’ll make sure it’s configured right
t
Ok thanks will do tomorrow and link here.
🙏🏻 1