Last active
August 21, 2017 12:52
-
-
Save AkshayChordiya/996478faac134a1457efc2003d82f75f to your computer and use it in GitHub Desktop.
UserViewModel with LiveData map transformation
This file contains hidden or 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 UserViewModel() : ViewModel() { | |
/** | |
* The user | |
*/ | |
private var user: LiveData<User> | |
/** | |
* Full name of the user | |
*/ | |
private var userFullName: LiveData<String> | |
init { | |
// Update the full name when user is changed | |
userFullName = Transformations.map(user) { user -> "$user.firstName $user.lastName" } | |
} | |
/** | |
* Get the data | |
*/ | |
fun getUser() = user | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could it be, you wanted a setter for
user
and a getter foruserFullName
here?