https://kotlinlang.org logo
Title
j

Jilles van Gurp

12/17/2020, 4:32 PM
I have a question regarding the RootStore. I noticed that after an update, current still reflects the old value because it updates asynchronously. So you can't read your own writes consistently currently.
update("xx")
println(current) // prints old value

update("yy")
delay(1000)
println(current) // prints yy
I solved it in my store by also putting the value in a private variable but that feels a bit ugly. Would it be possible to make this more consistent/less flaky?
j

Jan Weidenhaupt

03/02/2021, 7:26 PM
You should be careful with
myStore.current
, because the internal data only gets updated, when the
myStore.data
flow get collected (rendered or watched). Therefore you should avoid using
current
. Instead use the
data
flow and the functional-way it is more safe 😉 Sometimes it's easier to get the
current
value directly, that is why we left this possibility open, but then you must be sure that your data gets updated before correctly.