I would like to collect multiple different flows i...
# compose
l
I would like to collect multiple different flows into a single state class in presenter class and expose this single state to composable side. I have an approach but it might be done better: composable:
Copy code
@Composable
fun MyScreen() {
    val lifecycleOwner = LocalLifecycleOwner.current
    DisposableEffect(Unit) {
        myPresenter.collectFlows(lifecycleOwner)
        ...
    }
}
presenter:
Copy code
class MyPresenter {
    ...
    fun collectFlows(lifecycleOwner: LifecycleOwner) {
        lifecycleOwner.lifecycleScope.launch {
            lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
                val lifecycleScope = this

                /* Filter state */
                myFilterObservable()
                    .onEach { filter ->
                        myStateMutableFlow.update { prevState ->
                            prevState.copy(filterState = filter)
                        }
                    }
                    .launchIn(lifecycleScope)

               ... more flows to collect
            }
        }
    }
}
The reason why I do not use Flow.combine: some flows do not emit an initial value + I have state that is non-flow which I would have to convert to flow to use it with combine. Have a looh please and tell me if this can be done better. Maybe another approach would suit better for this use case. Thanks in advance