Extended set of extensions for dealing with LiveData.
ℹ️ Since Kotlin Coroutines 1.4.0 you can use StateFlow instead of LiveData to hold screen state in this case you don't want this library.
Add the dependency:
repositories {
mavenCentral()
google()
}
dependencies {
implementation("com.redmadrobot.extensions:lifecycle-livedata-ktx:2.3.1-0")
}This library applies next dependencies, so you don't need to apply it manually:
androidx.lifecycle:lifecycle-livedata-ktx:2.3.1androidx.lifecycle:lifecycle-livedata-core-ktx:2.3.1
Also, it depends on:
androidx.activity:activity:1.2.3androidx.annotation:annotation:1.2.0androidx.fragment:fragment:1.3.5
| Extension | Description |
|---|---|
|
Get non-null value or throw exception |
|
Sequential call of map and distinctUntilChanged |
|
Shorter way to observe LiveData in a fragment |
|
Shorter way to observe LiveData in an activity |
To access value in LiveData you can use delegate:
import com.redmadrobot.extensions.lifecycle.provideDelegate
val liveData = MutableLiveData<SomeViewState>(initialState)
var state: SomeViewState by liveDataMerge requests are welcome. For major changes, please open an issue first to discuss what you would like to change.