-
A
ViewModel
for a new screen needs to extentViewModel
from Android Arcitecture Components. Following all the work done by aViewModel
is delegated toUseCase
s that are responsible to fetch/update/modify data. -
A
ViewModel
should not "talk" directly to any other application layer rather thanUseCases/Interactors
. -
A
ViewModel
should accept UI intents through aConflatedBroadcastChannel
. Those events are then processed as aFlow
and are processed on theviewModelScope
. -
A
ViewModel
should observe results from aUseCase
and process them onviewModelScope
before delegating them to UI in the form ofLiveData
. -
A
ViewModel
should output any one-off actions to the UI in the form of*UIEvent
. Those*UIEvents
are propagated through a differentLiveData
stream and can be something that can describe a UI event, like:Show a success snackbar/toast
.