We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bb3c042 commit f78dc43Copy full SHA for f78dc43
common/src/main/java/me/li2/android/common/arch/ViewModelExt.kt
@@ -1,5 +1,6 @@
1
package me.li2.android.common.arch
2
3
+import androidx.lifecycle.MutableLiveData
4
import androidx.lifecycle.ViewModel
5
import androidx.lifecycle.viewModelScope
6
import kotlinx.coroutines.CoroutineScope
@@ -19,4 +20,16 @@ fun ViewModel.io(
19
20
}
21
22
-}
23
+}
24
+
25
+fun <T> ViewModel.ioWithState(
26
+ state: MutableLiveData<Resource<T>>,
27
+ ioHandler: suspend () -> T
28
+) {
29
+ state.postLoading()
30
+ io({
31
+ state.postError(this)
32
+ }) {
33
+ state.postSuccess(ioHandler())
34
+ }
35
0 commit comments