Lilly
05/12/2021, 5:54 PMStateFlow
and MutableState
in viewmodel/presenter layer? Is there a rule of thumb when to use one over the other, are there any drawbacks to use the one or the other? It seems to me both work the same wayAdam Powell
05/12/2021, 7:19 PM[Mutable]State
for things consumed by your UI. If you need a Flow
somewhere you can use snapshotFlow {}
to get one.Adam Powell
05/12/2021, 7:20 PMAdam Powell
05/12/2021, 7:21 PM.collectAsState
simply collects the flow and copies it into a State<T>
anyway, so using mutableStateOf
directly instead saves some steps.Lilly
05/12/2021, 8:54 PMJason Ankers
05/13/2021, 2:38 AMval uiState = combine(source1, source2, source3) {
emit(UiState.Loaded)
}.onStart {
emit(UiState.Loading)
}.catch {
emit(UiState.Error)
}
Adam Powell
05/13/2021, 2:43 PMval isLoaded: Boolean
get() = source1 != null && source2 != null && source3 != null
or replace the null with whatever other initial-value sentinel you might be using. No special API needed, just plain Kotlin.efemoney
05/15/2021, 2:00 PM[Mutable]State
be used in common code (yet)?
Say the same presenter object is to be shared across platforms, doe this answer still hold for whether to expose StateFlow or MutableState?Adam Powell
05/15/2021, 2:11 PMfrankelot
06/10/2021, 10:30 AM[Mutable]State
over StateFlow
, are there any good reasons for when to favor StateFlow