-
- All Implemented Interfaces:
-
pro.respawn.flowmvi.MVIProvider,pro.respawn.flowmvi.ReducerScope
public abstract class MVIViewModel<S extends MVIState, I extends MVIIntent, A extends MVIAction> extends ViewModel implements ReducerScope<S, I, A>, MVIProvider<S, I, A>
A ViewModel that uses MVIStore internally to provide a convenient base class. Only functions of the MVIProvider are made public, everything else happens through intents and actions. Exposing other public functions / streams is discouraged. You can inject this view model into the MVIView.provider field. If you want to add error handling for reduce, override recover (default implementation throws immediately)
-
-
Constructor Summary
Constructors Constructor Description MVIViewModel(S initialState)
-
Method Summary
Modifier and Type Method Description <ERROR CLASS>getScope()Flow<A>getActions()StateFlow<S>getStates()SgetState()Unitsend(I intent)Unitsend(A action)<R extends Any> RwithState(SuspendFunction1<S, R> block)Job,SuspendFunction1)>launchRecovering(CoroutineContext context, CoroutineStart start, <ERROR CLASS><S> recover, SuspendFunction1<CoroutineScope, Unit> block)SupdateState(SuspendFunction1<S, S> transform)Delegates to MVIStore.updateState -
-
Constructor Detail
-
MVIViewModel
MVIViewModel(S initialState)
- Parameters:
initialState- the state to set when creating the view model.
-
-
Method Detail
-
getScope
<ERROR CLASS> getScope()
-
getActions
Flow<A> getActions()
-
launchRecovering
Job ,SuspendFunction1)>launchRecovering(CoroutineContext context, CoroutineStart start, <ERROR CLASS><S> recover, SuspendFunction1<CoroutineScope, Unit> block)
-
updateState
S updateState(SuspendFunction1<S, S> transform)
Delegates to MVIStore.updateState
-
-
-
-