Base View Model
abstract class BaseViewModel<VS : ViewState> : ViewModel, LifecycleObserver
Content copied to clipboard
Base class representing ViewModel. It allows to observe LiveDatas, which is useful for observing ViewState. Observers are automatically removed when ViewModel is no longer used and will be destroyed. Beside that, it handles one-shot Events send from ViewModel to Activity/Fragment.
Constructors
BaseViewModel
Link copied to clipboard
fun BaseViewModel()
Content copied to clipboard
Functions
clear
Link copied to clipboard
observeEvent
Link copied to clipboard
fun observeEvent(lifecycleOwner: LifecycleOwner, eventClass: KClass<out Event<VS>>, observer: (Event<VS>) -> Unit)
Content copied to clipboard
Observe one-shot Event defined by event class and run observer lambda whenever event is received.
observeWithoutOwner
Link copied to clipboard
Observe LiveData without particular owner (Activity eg.).
fun <T : Any> DefaultValueLiveData<T>.observeWithoutOwner(callback: (T) -> Unit)
Content copied to clipboard
Observe DefaultValueLiveData without particular owner (Activity eg.).
fun <T : Any> DefaultValueMediatorLiveData<T>.observeWithoutOwner(callback: (T) -> Unit)
Content copied to clipboard
Observe DefaultValueMediatorLiveData without particular owner (Activity eg.).
setTagIfAbsent
Link copied to clipboard