From 5db8a419dea7ab7806d995d9b15bd005c8325560 Mon Sep 17 00:00:00 2001 From: William Brawner Date: Sun, 3 Jan 2021 07:56:43 -0700 Subject: [PATCH] Add helper method for updating state --- android/src/main/java/com/wbrawner/budget/AsyncState.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android/src/main/java/com/wbrawner/budget/AsyncState.kt b/android/src/main/java/com/wbrawner/budget/AsyncState.kt index 1a810e8..ada586e 100644 --- a/android/src/main/java/com/wbrawner/budget/AsyncState.kt +++ b/android/src/main/java/com/wbrawner/budget/AsyncState.kt @@ -21,6 +21,8 @@ interface AsyncViewModel { val state: MutableLiveData> } +fun MutableLiveData>.postValue(value: T) = postValue(AsyncState.Success(value)) + fun VM.launch(block: suspend () -> T): Job where VM : ViewModel, VM : AsyncViewModel = viewModelScope.launch { state.postValue(AsyncState.Loading) try {