Created
March 10, 2021 12:43
-
-
Save igorescodro/1f20e87e0ecb0b1a6e7782b8b848945d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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