Need help with LiveEvent?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

hadilq
323 Stars 24 Forks Apache License 2.0 70 Commits 1 Opened issues

Description

This library holds a class to handle single live events in Android MVVM architectural pattern. https://proandroiddev.com/livedata-with-single-events-2395dea972a8

Services available

!
?

Need anything else?

Contributors list

# 204,353
Kotlin
polymor...
Shell
kotlin-...
51 commits
# 646,932
Kotlin
2 commits
# 637,268
Ruby
Kotlin
1 commit
# 246,320
Java
Kotlin
Shell
jetpack...
1 commit

Health Check Maven Central

Live Event

This library holds a class to handle single live events in Android MVVM architectural pattern. This class is extended form LiveData class, from

androidx.lifecycle:lifecycle-extensions
library, to propagate the data as an event, which means it emits data just once, not after configuration changes again. Note that event will only be sent to active observers, any observers that started observing after the emit won't be notified of the event.

Usage

This source has a sample app where you can find

LiveEventViewModel
in it, in which the
LiveEvent
class is used as follows. ```kotlin class LiveEventViewModel : ViewModel() { private val clickedState = LiveEvent() val state: LiveData = clickedState
fun clicked() {
    clickedState.value = ...
}

} ```

LiveEventConfig

There are two behaviours of

LiveEvent
in-demand. First one is
LiveEventConfig.Normal
, where supports multi-observers on all cases the same. This config was originally implemented for this library so it's the default config, but if you want to be explicit, you can pass it to the constructor of
LiveEvent
.

The second config is

LiveEventConfig.PreferFirstObserver
. This one is useful when you want to emit an event in the
init
method of
ViewModel
and expect the first observer receive it. To set it up you need to pass it to the constructor
private val clickedState = LiveEvent(config = LiveEventConfig.PreferFirstObserver)

Download

Download via gradle

groovy
implementation "com.github.hadilq:live-event:$libVersion"
where you can find the
libVersion
in the Releases page of this repository.

Snapshots of the development version are available in Sonatype's snapshots repository.

Contribution

Just create your branch from the master branch, change it, write additional tests, satisfy all tests, create your pull request, thank you, you're awesome.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.