Tim Malseed
03/30/2021, 10:16 PMZach Klippenstein (he/him) [MOD]
03/30/2021, 10:18 PMmutableStateOf
takes a SnapshotMutationPolicy which lets you define both equality and merge behaviorZach Klippenstein (he/him) [MOD]
03/30/2021, 10:19 PMsnapshotFlow
)Tim Malseed
03/30/2021, 10:23 PMcollectAsState()
operator on a SharedFlow
, with objects whose equality is determined by their ID. The SharedFlow emits, but the layout doesn't recomposeTim Malseed
03/30/2021, 10:24 PMcollectasState
uses mutableStateOf
under the hood..Tim Malseed
03/30/2021, 10:29 PMcollectAsState
which accepts a SnapshotMutationPolicy
as an argument. I'll give that a goTim Malseed
03/30/2021, 10:33 PMLaunchedEffect
in produceState()
which is making the comparison in this case.Zach Klippenstein (he/him) [MOD]
03/30/2021, 10:48 PMcollectAsState
? Might answer your question easier than posting here 😉Zach Klippenstein (he/him) [MOD]
03/30/2021, 10:48 PMZach Klippenstein (he/him) [MOD]
03/30/2021, 10:49 PMcollectAsState
which uses a custom snapshot mutation policy, but the first question I would ask is why?Zach Klippenstein (he/him) [MOD]
03/30/2021, 10:50 PMZach Klippenstein (he/him) [MOD]
03/30/2021, 10:50 PMTim Malseed
03/30/2021, 10:53 PMZach Klippenstein (he/him) [MOD]
03/30/2021, 10:56 PM.equals
will check all the content afaik (e.g. function argument comparisons). If you can make it work, good for you, but i would definitely consider flipping that around and making the places that need to compare by ID only explicitly do so, and make equals
do the standard thing.Tim Malseed
03/30/2021, 11:12 PM.equals
will compare all fields. This is the default for a Kotlin data class, sure. Maybe it's a little too philosophical, and maybe my usual approach is flawed - but usually if I'm dealing with an object coming back from a database, I check equality based on the ID. If I need to know whether contents have changed (for example, RecyclerView DiffUtil), then I will add an additional 'contents comparison' check.
The assumption made by compose that .equals
checks all content is exactly the behaviour I'd like to override though. I think it's a little backwards to be designing my objects for their eventual composition/recomposition. But, I'm new to the compose way of thinking and I accept that I could be completely wrong about all of this!