nilTheDev
12/15/2021, 5:39 PMstateFlow emit changes when done in a nested value.
For context, consider this example,
data class Person(var name: String)
class SomeViewModel : ViewModel() {
// made public for brevity
val state = MutableStateFlow( listOf(Person("John")) )
init {
// will this change be emitted?
state.value[0].name = "Bob"
}
}
Will the change in the init block be emitted? I am pretty sure that liveData wouldn't emit this change. But would stateFlow do that?Nick Allen
12/15/2021, 6:02 PMvalue or call emit. And the new value has to be not equal to the old value or MutableStateFlow will ignore it. If you send the same instance, it'll be equal to itself, so that'll never emit.Nick Allen
12/15/2021, 6:03 PM