You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
val test = MutableLiveData("")
fun bind1() {
test.addObserver {
println("first $it")
if (it == "A") {
test.value = "B"
}
}
}
fun bind2() {
test.addObserver {
println("second $it")
}
}
fun start() {
bind1()
bind2()
test.value = "A"
}
After we call start function on iOS, in console we will see that observers calls in wrong order:
first A
first B
second B
second A
It happened because if we change value inside observer, changeValue function called recursively.
For workaround we can call observers with storedValue, as below
protected fun changeValue(value: T) {
storedValue = value
observers.forEach { it(storedValue) }
}
The text was updated successfully, but these errors were encountered:
code sample
After we call start function on iOS, in console we will see that observers calls in wrong order:
It happened because if we change value inside observer,
changeValue
function called recursively.For workaround we can call observers with
storedValue
, as belowThe text was updated successfully, but these errors were encountered: