Last active
February 6, 2020 02:03
-
-
Save paulocns/fb38a2cc4c06337e35fc3a319713ae61 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
abstract class BaseViewModel: ViewModel() { | |
protected operator fun <T> LiveData<T>.invoke(value: T) { | |
if (this is ViewModelLiveData) { | |
val viewModelLiveData = this | |
viewModelLiveData.setValue(value) | |
} | |
} | |
protected fun <T> liveData(value: T) = lazy { | |
ViewModelLiveData(value) as LiveData<T> | |
} | |
protected fun <T> liveData() = lazy { | |
ViewModelLiveData<T>() as LiveData<T> | |
} | |
private class ViewModelLiveData<T> : LiveData<T>{ | |
constructor(value: T) : super(value) | |
constructor() : super() | |
public override fun setValue(value: T) { | |
super.setValue(value) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment