Skip to content

Instantly share code, notes, and snippets.

@ChristopherME
Created June 25, 2020 03:26
Show Gist options
  • Save ChristopherME/f507aefe8a09145b0822de5c2c55da85 to your computer and use it in GitHub Desktop.
Save ChristopherME/f507aefe8a09145b0822de5c2c55da85 to your computer and use it in GitHub Desktop.
class SomeViewModel(
private val getUsersUseCase: GetUserUseCase,
private val mapper: PresentationMapper
) : ViewModel() {
// Only your viewmodel should update the value.
private val _users: MutableLiveData<List<PresentationUser>> = MutableLiveData()
val users: LiveData<List<PresentationUser>>
get() = _users
...
private fun executeUseCase() {
viewModelScope.launch {
val domainUsers = getUserUseCase.someComputation()
val presentationUsers = mapper.mapDomainUsersToPresentation(domainUsers)
_users.value = presentationUsers
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment