I am wondering whether `stateFlow` emit changes wh...
# coroutines
n
I am wondering whether
stateFlow
emit changes when done in a nested value. For context, consider this example,
Copy code
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?
🚫 3
n
You have to set
value
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.
I always try to send only immutable data through Flow.