Add helper method for updating state

This commit is contained in:
William Brawner 2021-01-03 07:56:43 -07:00
parent 98b44e4f59
commit 5db8a419de

View file

@ -21,6 +21,8 @@ interface AsyncViewModel<T> {
val state: MutableLiveData<AsyncState<T>>
}
fun <T> MutableLiveData<AsyncState<T>>.postValue(value: T) = postValue(AsyncState.Success(value))
fun <VM, T> VM.launch(block: suspend () -> T): Job where VM : ViewModel, VM : AsyncViewModel<T> = viewModelScope.launch {
state.postValue(AsyncState.Loading)
try {