Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 18, 2021. It is now read-only.
/ArchDataPublic archive

LiveData types for Publishing and Replaying Data

License

NotificationsYou must be signed in to change notification settings

ibrahimyilmaz/ArchData

Repository files navigation

Build StatusDownload

ArchData

ArchData provides two missing LiveData of Android Lifecycle Component and useful extension functions.

MutableLiveData shares only last state to its new observers when they start to observe.

But in some cases, either these observers may want to do fresh start or they want to get all previous states.

PublishLiveData andReplayLiveData types are extensions of MutableLiveData.

Basically:

  • PublishLiveData isMutableLiveData, which only notify its observers if there is an event after their starting of observation.
  • ReplayLiveData isMutableLiveData, which only notify its observers for all previous events happened before their observation starts.

Extension Functions:

  • nonNullObserve is extension function, which eliminates nullable invokes of Observer.

LiveDataAction:

  • LiveDataAction is special object type for LiveData,which enables observer can listen LiveData object without parameter.It is useful when Action/Command use cases.

Usage

  • PublishLiveData

    LiveData that, once anObserver has subscribed, emits all subsequently observed items to thesubscriber.

    val liveData=PublishLiveData<String>();// observer1 will receive all eventsliveData.observe(lifeCycleOwner,observer1)liveData.postValue("one")liveData.postValue("two")// observer2 will only receive "three"liveData.observe(lifeCycleOwner,observer2)liveData.postValue("three")
  • ReplayLiveData

    LiveData that buffers all items it observes and replays them to anyObserver that subscribes.

    val liveData=ReplayLiveData<String>()liveData.postValue("one")liveData.postValue("two")liveData.postValue("three")// both of the following will get the events from aboveliveData.observe(lifeCycleOwner,observer1)liveData.postValue(lifeCycleOwner,observer2)
  • nonNullObserve

    observe method which eliminates nullable invocation of observers.

    val liveData=MutableLiveData<String>()...viewModel.liveData.nonNullObserve(lifeCycleOwner,::onLiveDataEvent)...funonLiveDataEvent(event:String){//Do something good!.}
  • LiveDataAction

    Object Type which enables invocation listener methods without parameter

    val liveData=MutableLiveData<LiveDataAction>()...viewModel.liveData.nonNullObserve(lifeCycleOwner,::onLiveDataAction)...funonLiveDataEvent(){//Do something really good!.}

Download

Maven:

<dependency>  <groupId>me.ibrahimyilmaz</groupId>  <artifactId>ArchData</artifactId>  <version>0.0.4</version>  <type>pom</type></dependency>

Gradle:

compile'me.ibrahimyilmaz:ArchData:0.0.4'

License

MIT LicenseCopyright (c) [2019] [IBRAHIM YILMAZ | cs.ibrahimyilmaz@gmail.com]Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.

About

LiveData types for Publishing and Replaying Data

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp