fishy
09/25/2026, 7:55 AMremember {
snapshotFlow { state }.mapLatest { state ->
heavyComputation(state) // indirect, will only update when the flow value updates
}.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
}.collectAsState(sensibleDefault)
and
remember {
derivedStateOf {
heavyComputation(state) // direct capture, automatically updates
}
}Winson Chiu
09/25/2026, 7:44 PMState directly you could use snapshotFlow inside of produceState, which lets you change dispatchers.fishy
09/25/2026, 8:20 PMfishy
09/25/2026, 8:21 PMremember {
snapshotFlow { state }.mapLatest { state ->
heavyComputation(state) // indirect, requires all state reads to be able to be passed as a parameter to heavyComputation
}.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
}.collectAsState(sensibleDefault)
// versus
remember {
derivedStateOf {
heavyComputation() // heavyComputation can do its own state reads and they'll be tracked correctly
}
}Winson Chiu
09/25/2026, 8:27 PMfishy
09/25/2026, 8:32 PMnull, emptyList(), etc.)Winson Chiu
09/25/2026, 8:34 PMheavyComputation running synchronously with the caller that launched the Molecule. This is how it can return a StateFlow without asking for an initialValue. You'd have to adjust this to run on the background dispatcher.