Git Product home page Git Product logo

liveevent's Introduction

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.

class LiveEventViewModel : ViewModel() {
    private val clickedState = LiveEvent<String>()
    val state: LiveData<String> = 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<String>(config = LiveEventConfig.PreferFirstObserver)

Download

Download via gradle

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.

liveevent's People

Contributors

hadilq avatar ujavid avatar aasitnikov avatar kcrimi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.