Skip to content

Instantly share code, notes, and snippets.

@YuanLiou
Created February 2, 2021 16:04
Show Gist options
  • Save YuanLiou/3e5b11cfb492781c7ce3f16232c8279f to your computer and use it in GitHub Desktop.
Save YuanLiou/3e5b11cfb492781c7ce3f16232c8279f to your computer and use it in GitHub Desktop.
ViewEffect in ViewModel sample
// ViewState
sealed class ViewEffect {
data class ShowToast(val message: String) : ViewEffect()
}
// Set up LiveData
private val _viewEffectPublisher: MutableLiveData<Event<ViewEffect>>()
val viewEffectPublisher = LiveData<Event<ViewEffect>>
get() = _viewEffectPublisher
// Post an event
fun someMethod() {
_viewEffectPublisher.value = Event(ViewEffect.ShowToast("Hello!"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment