Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #6 from ibrahimyilmaz/kotlin_extensions
Browse files Browse the repository at this point in the history
nonNullObserver method is added.
  • Loading branch information
ibrahimyilmaz authored Jun 15, 2019
2 parents 4b51f94 + 11099b3 commit eb50f6e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/java/me/ibrahimyilmaz/arch_data/LiveDataExtensions.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package me.ibrahimyilmaz.arch_data

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer


inline fun <T> mutableLiveDataOf(): MutableLiveData<T> = MutableLiveData()

inline fun <T> publishLiveDataOf(): PublishLiveData<T> = PublishLiveData()

inline fun <T> replayLiveDataOf(): ReplayLiveData<T> = ReplayLiveData()
fun <T> mutableLiveDataOf(): MutableLiveData<T> = MutableLiveData()

fun <T> publishLiveDataOf(): PublishLiveData<T> = PublishLiveData()

fun <T> replayLiveDataOf(): ReplayLiveData<T> = ReplayLiveData()

fun <T> LiveData<T>.nonNullObserve(owner: LifecycleOwner, observer: (t: T) -> Unit) {
this.observe(owner, Observer {
it?.let(observer)
})
}

0 comments on commit eb50f6e

Please sign in to comment.