https://kotlinlang.org logo
#compose
Title
# compose
j

Jan

01/25/2022, 5:35 PM
I have a question for ViewModel. I know that I can just use something like that for getting the newest entries:
Copy code
class AbsenceViewModel : ViewModel() {

    val absencesFlow = MutableStateFlow<List<DBItem>>(emptyList())

    init {
        viewModelScope.launch {
            kotlin.runCatching {
                AbsenceRepository.getAll()
            }.onSuccess {
                absencesFlow.value = it.toList()
            }.onFailure {
                absencesFlow.value = emptyList()
            }
        }
    }

}
but whats when I modify the entries on the rest api? Or if I want to modify them locally?
Like I have this code currently:
Copy code
val viewModel by viewModels<AbsenceViewModel>()

val entries by viewModel.absencesFlow.collectAsState()
What if the entries in the rest api change or I like create a new entry and want to add it to the "entries"?
nvm