https://kotlinlang.org logo
#compose
Title
# compose
z

Zach Klippenstein (he/him) [MOD]

05/13/2022, 5:09 PM
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

Tolriq

05/13/2022, 6:08 PM
Do you have some part that talk about the mixing of remember and derivedStateOf?
z

Zach Klippenstein (he/him) [MOD]

05/13/2022, 6:22 PM
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

Tolriq

05/13/2022, 6:41 PM
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

lhwdev

05/14/2022, 3:12 AM
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

Zach Klippenstein (he/him) [MOD]

05/15/2022, 8:23 PM
@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

Tolriq

05/16/2022, 5:42 AM
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

Zach Klippenstein (he/him) [MOD]

05/16/2022, 4:48 PM
Fair enough. Could you file a bug? I’ll make sure it gets routed to the right people to update the docs.
t

Tolriq

05/16/2022, 4:50 PM
Yes I can, can you point me the right category ?
z

Zach Klippenstein (he/him) [MOD]

05/16/2022, 4:50 PM
just put it in Jetpack Compose and i’ll make sure it’s configured right
t

Tolriq

05/16/2022, 4:51 PM
Ok thanks will do tomorrow and link here.
🙏🏻 1
3 Views