Created
March 17, 2022 15:58
-
-
Save jhonatansabadi/3677b974b7bb0ae048e62f2872c62726 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 GetUserByIdUseCase( | |
private val dispatcher: CoroutineDispatcher = Dispatcher.IO, | |
private val userRepository: UserRepository | |
) { | |
suspend fun invoke(id: String): User { | |
return withContext(dispatcher) { | |
userRepository.getUserById(id) | |
} | |
} | |
} | |
class MyViewModel( | |
private val getUserByIdUseCase: GetUserByIdUseCase | |
): Viewmodel { | |
private val _user: MutableLiveData<User> | |
val _user: LiveData<User> | |
fun setUser(id: String) { | |
viewModelScope.launch { | |
_user.value = getUserByIdUseCase(id) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment