Created
February 2, 2021 16:04
-
-
Save YuanLiou/3e5b11cfb492781c7ce3f16232c8279f to your computer and use it in GitHub Desktop.
ViewEffect in ViewModel sample
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
// 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