vector / com.haroldadmin.vector / VectorViewModel
VectorViewModel¶
abstract class VectorViewModel<S :
VectorState
> :
ViewModel
The Base ViewModel class your ViewModel should inherit from
Parameters¶
S
- The state class for this ViewModel implementing VectorState
initialState
- The initial state for this ViewModel
stateStoreContext
-
The CoroutineContext to be used with the state store
A VectorViewModel can implement the VectorViewModelFactory in its Companion object to provide ways to create the initial state, as well as the ViewModel itself.
Constructors¶
Name | Summary |
---|---|
<init> | VectorViewModel(initialState: S , stateStoreContext: CoroutineContext = Dispatchers.Default + Job()) The Base ViewModel class your ViewModel should inherit from |
Properties¶
Name | Summary |
---|---|
currentState | val currentState: S Access the current value of state stored in the stateStore. |
logger | val logger: Logger |
state | val state: Flow< S > A kotlinx.coroutines.flow.Flow of VectorState which can be observed by external classes to respond to changes in state. |
stateStore | open val stateStore: StateStore < S > The state store associated with this ViewModel |
Functions¶
Name | Summary |
---|---|
onCleared | open fun onCleared(): Unit Clears this ViewModel as well as its stateStore. |
setState | fun setState(action: suspend S .() -> S ): Unit The only method through which state mutation is allowed in subclasses. |
withState | fun withState(action: suspend ( S ) -> Unit ): Unit Dispatch the given action the stateStore. This action shall be processed as soon as all existing state reducers have been processed. The state parameter supplied to this action should be the latest value at the time of processing of this action. |
Inheritors¶
Name | Summary |
---|---|
SavedStateVectorViewModel | abstract class SavedStateVectorViewModel<S : VectorState > : VectorViewModel < S > A Subclass of VectorViewModel that has access to a SavedStateHandle to easily persist state properties in case of process death |