I have come across a weird issue with compose Muta...
# compose-android
m
I have come across a weird issue with compose MutableState When we change a state value quickly back to the previous one, it is skipping the recomposition of intermediate value. Maybe this is intended behaviour, but not sure about it. Any insights on this would be appreciated. thanks.
s
That’s expected behavior, the state changes all before there’s a chance to have the new state be committed.
1
Maybe reading this https://dev.to/zachklipp/introduction-to-the-compose-snapshot-system-19cn could be interesting to you. I think what’s happening here is that the state changes, and then it changes again, but there was never a commit in-between these two changes so that new state is never read by all the observers of that state. In your case you composable which uses that state to print the log. Then since your state went from being
0
to now being
0
again, according to this blog “State changes are de-duplicated. If a state value is set to the same value, no change is recorded for that value. The logic that defines what values are considered “equal” can actually be customized via a policy, as we’ll see later in this post when we examine conflicting snapshot writes.“. So it sees those two states as equal (since they are) so there’s no reason for it to inform the observers about any state changes. There was no state change as far as all the observers were concerned.
y
If all intermediate states need to be processed, then you can put them in a Channel, and consuming in a launched effect.
m
Thanks for the insights and pointers on this @Stylianos Gakis and @yschimke 🙏🏻
z
Also, no matter what state tool you use or how often you update it, recomposition isn’t gonna happen until the choreographer starts the next frame.