Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //interface for view/fragment/activity/whatever
- interface LoginAcceptable {
- fun onChangeLocation()
- fun onLoginSuccess()
- fun onAppUpdateAvailable()
- fun renderLocationConfig(configuration: LocationConfiguration)
- }
- // typealias for livedata
- typealias LoginEvent = LoginAcceptable.() -> Unit
- // single livedata in viewModel
- val ui = MutableLiveData<LoginEvent>()
- // just syntax sugar
- operator fun <T> MutableLiveData<T>.invoke(value: T) {
- postValue(value)
- }
- // somewhere in ViewModel
- fun foo() {
- launch {
- val config = getConfig() // suspend function
- ui {
- renderLocationConfig(config)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement