BaseViewModel

abstract class BaseViewModel<VS : ViewState> : ViewModel, LifecycleObserver

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()

Functions

clear
Link copied to clipboard
fun clear()
equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
getTag
Link copied to clipboard
open fun <T : Any> getTag(p0: String): T
hashCode
Link copied to clipboard
open fun hashCode(): Int
observeEvent
Link copied to clipboard
fun observeEvent(lifecycleOwner: LifecycleOwner, eventClass: KClass<out Event<VS>>, observer: (Event<VS>) -> Unit)
Observe one-shot Event defined by event class and run observer lambda whenever event is received.
observeWithoutOwner
Link copied to clipboard
fun <T> LiveData<T>.observeWithoutOwner(callback: (T) -> Unit)
Observe LiveData without particular owner (Activity eg.).
fun <T : Any> DefaultValueLiveData<T>.observeWithoutOwner(callback: (T) -> Unit)
Observe DefaultValueLiveData without particular owner (Activity eg.).
fun <T : Any> DefaultValueMediatorLiveData<T>.observeWithoutOwner(callback: (T) -> Unit)
Observe DefaultValueMediatorLiveData without particular owner (Activity eg.).
onStart
Link copied to clipboard
open fun onStart()
Activity's onStart() method companion.
sendEvent
Link copied to clipboard
fun sendEvent(event: Event<VS>)
Send one-shot event to internal bus and notify all of its observers
setTagIfAbsent
Link copied to clipboard
open fun <T : Any> setTagIfAbsent(p0: String, p1: T): T
toString
Link copied to clipboard
open fun toString(): String

Properties

internalSavedStateHandle
Link copied to clipboard
var internalSavedStateHandle: SavedStateHandle? = null
requireSavedStateHandle
Link copied to clipboard
val requireSavedStateHandle: SavedStateHandle
viewState
Link copied to clipboard
abstract val viewState: VS