Michal Klimczak
05/29/2021, 1:26 PM//causes infinite recomposition
val playerUiStateWrong by player.observeState()
.map { PlayerUIState(it, sound) }
.collectAsState(PlayerUIState(null, null))
//works fine
val playerState by player.observeState().collectAsState(PlayerState.Stopped)
val playerUiState = PlayerUIState(playerState, sound)
I thought they would both do the same thing, but the first one, whenever I use playerUiStateWrong
as a parameter in a modifier, causes infinite recompositions, whereas the second one works fine.Adam Powell
05/29/2021, 1:47 PMAdam Powell
05/29/2021, 1:49 PMAdam Powell
05/29/2021, 1:50 PMremember
the assembled flow based on its inputs you'll see the same results as with your second snippet https://kotlinlang.slack.com/archives/CJLTWPH7S/p1622215590179700?thread_ts=1622212535.172400&cid=CJLTWPH7SMichal Klimczak
05/29/2021, 2:11 PMAdam Powell
05/29/2021, 2:22 PMAdam Powell
05/29/2021, 2:23 PMMichal Klimczak
05/29/2021, 2:30 PMMichal Klimczak
05/29/2021, 2:36 PMAdam Powell
05/29/2021, 2:44 PMZach Klippenstein (he/him) [MOD]
05/29/2021, 3:52 PMAdam Powell
05/29/2021, 4:30 PM@Stable
but it's not at all clear in all cases that any given pure function isn't cheaper to just perform on recomposition as opposed to performing parameter comparisons and storing a bunch of intermediate values in the compositionAdam Powell
05/29/2021, 4:32 PMAdam Powell
05/29/2021, 4:38 PMMichal Klimczak
05/31/2021, 2:29 PMMichal Klimczak
05/31/2021, 2:29 PM