Last active
June 25, 2020 03:37
-
-
Save ChristopherME/4049fe1e5d95284ec2b0b97e9c3dff0d to your computer and use it in GitHub Desktop.
This file contains 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
class SomeViewModel( | |
private val getUsersUseCase: GetUserUseCase, | |
private val mapper: PresentationMapper | |
) : ViewModel() { | |
// Only your viewmodel should update the value. | |
private val _domainUsers: MutableLiveData<List<DomainUser>> = MutableLiveData() | |
val users: LiveData<List<PresentationUser>> = _domainUsers.switchMap { domainUsers -> | |
liveData { | |
emit(mapper.mapDomainUsersToPresentation(domainUsers)) | |
} | |
} | |
// You can do what ever you want once you have the value. | |
val showEmptyView: LiveData<Boolean> = _domainUsers.map { domainUsers -> domainUsers.isNullOrEmpty() } | |
... | |
private fun executeUseCase() { | |
viewModelScope.launch { | |
_domainUsers.value = getUserUseCase.someComputation() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment