Alexandru Hadăr
06/16/2023, 3:43 PMprivate val _filtersState: MutableStateFlow<FiltersUiState> = MutableStateFlow(FiltersUiState.Loading)
val uiState: StateFlow<FiltersUiState> = _filtersState.asStateFlow()
init {
viewModelScope.launch {
transactionPreferences.transactionInfoStream
.onEach { _filtersState.update { FiltersUiState.Loading } }
.map {
filtersRepository.loadFilters(it)
.map { /* TODO map to UI filters */ }
}
.catch { ex -> _filtersState.update { FiltersUiState.Error(ex) } }
.collect()
}
}
Could I simplify this? It seems wrong having to update the UI manually, on onEach
,map
and catch