Eric Ampire [MOD]
09/04/2021, 8:54 PMprivate fun Flow<Result<List<Lottiefile>>>.fetchData() = intent(registerIdling = false) {
collect { result ->
when(result) {
is Result.Error -> {
Timber.e(result.toString())
val errorMessage = result.exception.localizedMessage ?: "Unknown Error"
reduce { state.copy(isLoading = false) }
postSideEffect(ExploreEffect.ShowErrorMessage(errorMessage))
}
Result.Loading -> {
Timber.e(result.toString())
reduce { state.copy(isLoading = true) }
}
is Result.Success -> {
Timber.e(result.toString())
reduce { state.copy(files = result.data, isLoading = false) }
}
}
}
}
The state is collected like that
val state by viewModel.container.stateFlow.collectAsState()
Mikolaj Leszczynski
09/06/2021, 6:26 AMcontainer
field?Oleksii Malovanyi
09/06/2021, 7:11 AMFlow<Result>
-> try removing the Result from the typeEric Ampire [MOD]
09/06/2021, 7:20 PMOleksii Malovanyi
09/06/2021, 7:30 PMintent{}
-> remove get() in favour of property initializerEric Ampire [MOD]
09/06/2021, 10:03 PM