Skip to content

Instantly share code, notes, and snippets.

@igorescodro
Last active March 10, 2021 14:09
Show Gist options
  • Save igorescodro/6a328ea4ed9a4737a88bad0ec25d5887 to your computer and use it in GitHub Desktop.
Save igorescodro/6a328ea4ed9a4737a88bad0ec25d5887 to your computer and use it in GitHub Desktop.
val state: StateFlow<TaskListViewState> = flow {
loadAllTasksUseCase().collect { tasks ->
val state = if (tasks.isNotEmpty()) {
TaskListViewState.Loaded(tasks)
} else {
TaskListViewState.Empty
}
emit(state)
}
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), TaskListViewState.Empty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment