vector / com.haroldadmin.vector / SavedStateVectorViewModel
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
Parameters¶
initialState
- The initial state for this ViewModel
stateStoreContext
- The CoroutineContext to be used with the contained State Store
savedStateHandle
- The SavedStateHandle to be used for persisting state across process deaths
Constructors¶
Name | Summary |
---|---|
<init> | SavedStateVectorViewModel(initialState: S , stateStoreContext: CoroutineContext = Dispatchers.Default + Job(), savedStateHandle: SavedStateHandle ) A Subclass of VectorViewModel that has access to a SavedStateHandle to easily persist state properties in case of process death |
Properties¶
Name | Summary |
---|---|
savedStateHandle | val savedStateHandle: SavedStateHandle The SavedStateHandle to be used for persisting state across process deaths |
Inherited 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 |
---|---|
persistState | open fun persistState(): Unit Saves the current state into savedStateHandle using KEY_SAVED_STATE Subclasses can override this method for custom behaviour. |
setStateAndPersist | fun setStateAndPersist(reducer: suspend S .() -> S ): Unit A convenience wrapper around the setState function which runs the given reducer, and then persists the newly created state |
Inherited 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. |
Companion Object Properties¶
Name | Summary |
---|---|
KEY_SAVED_STATE | const val KEY_SAVED_STATE: String A predefined key which can be used to persist a valid VectorState class into the savedStateHandle |