Skip to content

Commit b8d51b0

Browse files
committed
release: v0.0.1
1 parent edf7e36 commit b8d51b0

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

mvvm/src/main/java/com/arduia/mvvm/Event.kt

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ package com.arduia.mvvm
1919

2020
import androidx.lifecycle.Observer
2121

22-
22+
/**
23+
* Event State with data that can be consumed once.
24+
*/
2325
open class Event<out T> (private val content: T){
2426

2527
var hasHandled = false
@@ -37,7 +39,9 @@ open class Event<out T> (private val content: T){
3739
fun peekContent(): T = content
3840
}
3941

40-
42+
/**
43+
* Observer that consume {@link Event} Data
44+
*/
4145
class EventObserver<T> (private val onEventUnhandledContent: (T)-> Unit): Observer<Event<T>>{
4246

4347
override fun onChanged(event: Event<T>?) {
@@ -47,6 +51,10 @@ class EventObserver<T> (private val onEventUnhandledContent: (T)-> Unit): Observ
4751
}
4852
}
4953

54+
/**
55+
* For State Event that represent state with no data.
56+
*/
5057
val EventUnit get() = Event(Unit)
5158

59+
5260
fun <T>event(content: T) = Event(content)

mvvm/src/main/java/com/arduia/mvvm/LiveData.kt

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ package com.arduia.mvvm
2020
import androidx.lifecycle.LiveData
2121
import androidx.lifecycle.MutableLiveData
2222

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+
*/
2331

2432
class BaseLiveData<T> : MutableLiveData<T>(){
2533
fun asLiveData(): LiveData<T> = this

0 commit comments

Comments
 (0)