It was a simple type definition problem.
You defined cache
as LiveData<ViewState.Success<T>>
which does not match the returning type of LiveData<ViewState<T>>
.
You have to change the type from val cache: LiveData<ViewState.Success<T>>
to val cache: LiveData<ViewState<T>>
.
Here is the correct functions:
fun <T, A> performGetOperation(databaseQuery: () -> LiveData<T>)): LiveData<ViewState<T>> = liveData(Dispatchers.IO) {
emit(ViewState.Loading)
val cache: LiveData<ViewState<T>> = databaseQuery.invoke()
.map { ViewState.Success<T>(it) }
emitSource(cache)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…