Skip to content

Instantly share code, notes, and snippets.

@Zhuinden
Created November 27, 2019 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zhuinden/20cd4b8b497f595eee7d4dc8a5333f48 to your computer and use it in GitHub Desktop.
Save Zhuinden/20cd4b8b497f595eee7d4dc8a5333f48 to your computer and use it in GitHub Desktop.
Anemic Repository 3
class MyViewModel(
savedStateHandle: SavedStateHandle,
private val userDao: UserDao
): ViewModel() {
private val selectedUserId: MutableLiveData<String> =
savedStateHandle.getLiveData("selectedUserId")
val selectedUser: LiveData<User> = selectedUserId.switchMap { id ->
userDao.getUserByIdWithChanges(id)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment