https://kotlinlang.org logo
#coroutines
Title
# coroutines
g

Gabriel Feo

07/24/2020, 9:51 PM
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

dekans

07/25/2020, 6:17 PM
Take a look at StateFlow
5 Views