Last active
July 11, 2020 21:52
-
-
Save GregKluska/e935fea7585febc40f81d5b043bac4c6 to your computer and use it in GitHub Desktop.
A LiveData class that has `null` value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import androidx.lifecycle.LiveData | |
| /** | |
| * A LiveData class that has `null` value. | |
| */ | |
| class AbsentLiveData<T : Any?> private constructor(): LiveData<T>() { | |
| init { | |
| // use post instead of set since this can be created on any thread | |
| postValue(null) | |
| } | |
| companion object { | |
| fun <T> create(): LiveData<T> { | |
| return AbsentLiveData() | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment