Benoît
11/29/2023, 1:36 PMfun <S : Any> ContainerHost<S, *>.observeFlow(
flow: Flow<String>,
block: S.(String) -> S
) {
intent {
flow.collectLatest { data ->
reduce {
state.block(data)
}
}
}
}
Or is it better to do it in a CoroutineScope like this:
fun <S : Any> ContainerHost<S, *>.observeFlow(
flow: Flow<String>,
scope: CoroutineScope,
block: S.(String) -> S
) {
scope.launch {
flow.collectLatest { data ->
intent {
reduce {
state.block(data)
}
}
}
}
}
agrosner
11/29/2023, 2:49 PMMikolaj Leszczynski
12/06/2023, 2:25 PMrepeatOnSubscription
if the state doesn't need to be updated when there's no UI though (e.g. app backgrounded).
I certainly do not recommend the latter, passing scopes in from the outside is generally something I personally consider a code smell, as it kinda circumvents the structured concurrency paradigm.