Advertisement
Guest User

Untitled

a guest
Feb 13th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.67 KB | None | 0 0
  1. //interface for view/fragment/activity/whatever
  2. interface LoginAcceptable {
  3.     fun onChangeLocation()
  4.     fun onLoginSuccess()
  5.     fun onAppUpdateAvailable()
  6.     fun renderLocationConfig(configuration: LocationConfiguration)
  7. }
  8.  
  9. // typealias for livedata
  10. typealias LoginEvent = LoginAcceptable.() -> Unit
  11.  
  12. // single livedata in viewModel
  13. val ui = MutableLiveData<LoginEvent>()
  14.  
  15. // just syntax sugar
  16. operator fun <T> MutableLiveData<T>.invoke(value: T) {
  17.     postValue(value)
  18. }
  19.  
  20.  
  21. // somewhere in ViewModel
  22. fun foo() {
  23.     launch {
  24.         val config = getConfig() // suspend function
  25.         ui {
  26.            renderLocationConfig(config)      
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement