Skip to content

Instantly share code, notes, and snippets.

@hadilq
Created February 5, 2020 17:26
Show Gist options
  • Save hadilq/b9a61c10aa63cd78d75157f960928efa to your computer and use it in GitHub Desktop.
Save hadilq/b9a61c10aa63cd78d75157f960928efa to your computer and use it in GitHub Desktop.
RxViewModelSample
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