Skip to content

Instantly share code, notes, and snippets.

@igorescodro
Created March 10, 2021 12:43
Show Gist options
  • Save igorescodro/1f20e87e0ecb0b1a6e7782b8b848945d to your computer and use it in GitHub Desktop.
Save igorescodro/1f20e87e0ecb0b1a6e7782b8b848945d to your computer and use it in GitHub Desktop.
internal class TaskListViewModel : ViewModel() {
private val _state = MutableStateFlow<TaskListViewState>(TaskListViewState.Empty)
val state: StateFlow<TaskListViewState>
get() = _state
fun loadTasks() = viewModelScope.launch {
loadAllTasksUseCase().collect { tasks ->
_state.value = if (tasks.isNotEmpty()) {
TaskListViewState.Loaded(tasks)
} else {
TaskListViewState.Empty
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment