StateFlow does not emit an updated object value if a property of the object is changed, is this the intentional design? Example:
Copy code
data class Count(var value: Int = 0)
private val count = MutableStateFlow(Count())
val newCount = count.value
newCount.value++ // no emission though value is updated
count.value = newCount // this does not emit either
👌 4
z
Zach Klippenstein (he/him) [MOD]
07/18/2020, 4:49 AM
Yes. Updating the property doesn't emit because the flow has no way of knowing anything happened. Then sending the same object back into the flow doesn't emit because the flow now sees that the new value is equal to the old value.
In general, reactive streams work best with immutable "value" objects.
t
tjohnn
07/18/2020, 6:00 AM
Okay thanks Zac
m
Mark Murphy
07/18/2020, 11:41 AM
Beyond that,
StateFlow
uses content equality (
==
) and only emits values when the object contents differ.
See "Strong equality-based conflation" in the