Created
February 5, 2020 17:26
-
-
Save hadilq/b9a61c10aa63cd78d75157f960928efa to your computer and use it in GitHub Desktop.
RxViewModelSample
This file contains 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
class RxViewModelSample : ViewModel() { | |
private val publisher = PublishProcessor.create<String>() | |
private val extendedPublisher = BehaviorProcessor.create<String>().apply { onNext("Test") } | |
/** | |
* The value of this emitter would NOT be saved on onSaveInstanceState | |
*/ | |
val stringEmitter = publisher.toLifecycleAware() | |
/** | |
* The value of this emitter would be saved on onSaveInstanceState | |
*/ | |
val extendedStringEmitter = extendedPublisher.toExtendedLifecycleAware(KEY) | |
companion object { | |
private const val KEY = "key_to_save_string_emitter" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment