Add helper method for updating state
This commit is contained in:
parent
98b44e4f59
commit
5db8a419de
1 changed files with 2 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue