-
public abstract class MavericksViewModel<S extends MavericksState>All Mavericks ViewModels must extend this class. In Mavericks, ViewModels are generic on a single state class. The ViewModel owns all state modifications via setState and other classes may observe the state.
From a MavericksView/Fragment, using the view model provider delegates will automatically subscribe to state updates in a lifecycle-aware way and call MavericksView.invalidate whenever it changes.
Other classes can observe the state via stateFlow.
-
-
Field Summary
Fields Modifier and Type Field Description private final MavericksViewModelConfig<S>configprivate final CoroutineScopeviewModelScopeprivate final Flow<S>stateFlow
-
Constructor Summary
Constructors Constructor Description MavericksViewModel(S initialState, MavericksViewModelConfigFactory configFactory)
-
Method Summary
Modifier and Type Method Description final MavericksViewModelConfig<S>getConfig()final CoroutineScopegetViewModelScope()final Flow<S>getStateFlow()UnitonCleared()final SawaitState()Calling this function suspends until all pending setState reducers are run and then returns the latest state. StringtoString()-
-
Constructor Detail
-
MavericksViewModel
MavericksViewModel(S initialState, MavericksViewModelConfigFactory configFactory)
-
-
Method Detail
-
getConfig
final MavericksViewModelConfig<S> getConfig()
-
getViewModelScope
final CoroutineScope getViewModelScope()
-
getStateFlow
final Flow<S> getStateFlow()
-
awaitState
final S awaitState()
Calling this function suspends until all pending setState reducers are run and then returns the latest state. As a result, it is safe to call setState { } and assume that the result from a subsequent awaitState() call will have that state.
-
-
-
-