Are there any examples to understand “recompositio...
# compose
p
Are there any examples to understand “recomposition is optimistic” ? https://developer.android.google.cn/jetpack/compose/mental-model?authuser=0#optimistic
s
I don’t have any examples, but as I understand it, this is basically a way of saying that one should not depend on side effects running in composition for correctness, as recompositions may be discarded at any point. So plan accordingly and don’t rely on such side-effects.
👍 1
p
thank you~ . I want to write a sample to simulate a case that recomposition is discarded , but I can’t 😂
s
You could do a
throw Exception
from inside a composable, that should make a composition fail maybe?
Doing a quick search inside this channel brought up this message, so I guess yes, this should make a recomposition fail.
p
thank you ,very helpful~
z
I believe you can also use
SubcomposeLayout
to “precompose” something and then discard that composition before actually using it in layout. Lazy lists might do this if you change scroll direction in the middle of a scroll.