File tree 2 files changed +18
-2
lines changed
mvvm/src/main/java/com/arduia/mvvm
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,9 @@ package com.arduia.mvvm
19
19
20
20
import androidx.lifecycle.Observer
21
21
22
-
22
+ /* *
23
+ * Event State with data that can be consumed once.
24
+ */
23
25
open class Event <out T > (private val content : T ){
24
26
25
27
var hasHandled = false
@@ -37,7 +39,9 @@ open class Event<out T> (private val content: T){
37
39
fun peekContent (): T = content
38
40
}
39
41
40
-
42
+ /* *
43
+ * Observer that consume {@link Event} Data
44
+ */
41
45
class EventObserver <T > (private val onEventUnhandledContent : (T )-> Unit ): Observer<Event<T>>{
42
46
43
47
override fun onChanged (event : Event <T >? ) {
@@ -47,6 +51,10 @@ class EventObserver<T> (private val onEventUnhandledContent: (T)-> Unit): Observ
47
51
}
48
52
}
49
53
54
+ /* *
55
+ * For State Event that represent state with no data.
56
+ */
50
57
val EventUnit get() = Event (Unit )
51
58
59
+
52
60
fun <T >event (content : T ) = Event (content)
Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ package com.arduia.mvvm
20
20
import androidx.lifecycle.LiveData
21
21
import androidx.lifecycle.MutableLiveData
22
22
23
+ /* *
24
+ * Base MutableLiveData that has LiveData casting with
25
+ * fun asLiveData() to use for encapsulations such as:
26
+ *
27
+ * Example -
28
+ * private val _data = BaseLiveData<String>();
29
+ * val data = _data.asLiveData()
30
+ */
23
31
24
32
class BaseLiveData <T > : MutableLiveData <T >(){
25
33
fun asLiveData (): LiveData <T > = this
You can’t perform that action at this time.
0 commit comments