https://kotlinlang.org logo
Title
p

Peng Wang

04/26/2022, 11:11 AM
Are there any examples to understand “recomposition is optimistic” ? https://developer.android.google.cn/jetpack/compose/mental-model?authuser=0#optimistic
s

Stylianos Gakis

04/26/2022, 2:21 PM
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

Peng Wang

04/26/2022, 3:02 PM
thank you~ . I want to write a sample to simulate a case that recomposition is discarded , but I can’t 😂
s

Stylianos Gakis

04/26/2022, 3:05 PM
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

Peng Wang

04/26/2022, 3:35 PM
thank you ,very helpful~
z

Zach Klippenstein (he/him) [MOD]

04/26/2022, 6:15 PM
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.