Skip to content

Commit

Permalink
feat: Add notifyObservers() for MutableLiveData and NonNullLiveData
Browse files Browse the repository at this point in the history
  • Loading branch information
percula committed Oct 11, 2019
1 parent d3fb8a1 commit f739195
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion library/src/main/java/dev/percula/ktx/LiveData.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.percula.ktx

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations

@Deprecated(
Expand All @@ -15,4 +16,9 @@ fun <X, Y> LiveData<X>.map(mapFunction: (value: X?) -> Y?) =
ReplaceWith("Transformations.switchMap(this, mapFunction)", "androidx.lifecycle.Transformations")
)
fun <X, Y> LiveData<X>.switchMap(mapFunction: (value: X?) -> LiveData<Y>): LiveData<Y> =
Transformations.switchMap(this, mapFunction)
Transformations.switchMap(this, mapFunction)

fun <T> MutableLiveData<T>.notifyObservers(): MutableLiveData<T> {
value = value
return this
}
5 changes: 5 additions & 0 deletions library/src/main/java/dev/percula/ktx/NonNullLiveData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ open class NonNullLiveData<T>(private val initialValue: T): LiveData<T>() {
return super.getValue() ?: initialValue
}

fun notifyObservers(): NonNullLiveData<T> {
value = value
return this
}

}

0 comments on commit f739195

Please sign in to comment.