-
Notifications
You must be signed in to change notification settings - Fork 3
3. EventViewModel
Gabriel Brasileiro edited this page Jun 13, 2020
·
4 revisions
EventViewModel manages and make interactions with Reducer and SingleLiveData*.
The implementation of EventViewModel need receive a SingleLiveData<Event>(With event interface) to works correctly.
To send events all you need is call the method sendEvent(Event) passing your respective event.
Event implementation checklist:
- Extend your event implementation from the
Eventinterface.
See Event doc to understand better.
Example:
class LoadViewModel(
event: SingleLiveEvent<LoadEvent>
// private val anyUseCase: AnyUseCase
) : EventViewModel<LoadEvent>(event) {
fun showLoader() {
sendEvent(LoadEvent.ShowLoader)
}
fun hideLoader() {
sendEvent(LoadEvent.HideLoader)
}
}Read about listener extensions to process LiveData of your view models with simple way.