I'm refactoring an app for a unidirectional data f...
# coroutines
g
I'm refactoring an app for a unidirectional data flow between the View and the ViewModel, I'd like to get some opinions on this, I think there's probably a better way to declare this Flow.
Copy code
data class State(action: Action, list: ListState)

fun getState(events: Flow<ViewEvent>): Flow<State> {
    return combine(
        getActionState(events).onStart { emit(Action.None) },
        getListState().onStart { emit(ListState.Loading) }
    ) { action, lovedOnesState ->
        State(action, lovedOnesState)
    }
}
If a ListState change causes a new State to be emitted, the next ViewEvents need to be reduced against this new State, and vice-versa, that's why I combine
d
Take a look at StateFlow