-
public abstract class MavericksViewModelConfig<S extends Object>Provides configuration for a MavericksViewModel.
-
-
Field Summary
Fields Modifier and Type Field Description private final BooleandebugModeprivate final MavericksStateStore<S>stateStoreprivate final CoroutineScopecoroutineScopeprivate final CoroutineContextsubscriptionCoroutineContextOverride
-
Constructor Summary
Constructors Constructor Description MavericksViewModelConfig(Boolean debugMode, MavericksStateStore<S> stateStore, CoroutineScope coroutineScope, CoroutineContext subscriptionCoroutineContextOverride)
-
Method Summary
Modifier and Type Method Description final BooleangetDebugMode()If true, extra validations will be applied to ensure the view model is used correctly. final MavericksStateStore<S>getStateStore()The state store instance that will control the state of the ViewModel. final CoroutineScopegetCoroutineScope()The coroutine scope that will be provided to the view model. final CoroutineContextgetSubscriptionCoroutineContextOverride()Provide a context that will be added to the coroutine scope when a subscription is registered (eg MavericksView.onEach). abstract <S extends MavericksState> MavericksBlockExecutionsonExecute(MavericksViewModel<S> viewModel)Called each time a MavericksRepository.execute function is invoked. -
-
Constructor Detail
-
MavericksViewModelConfig
MavericksViewModelConfig(Boolean debugMode, MavericksStateStore<S> stateStore, CoroutineScope coroutineScope, CoroutineContext subscriptionCoroutineContextOverride)
-
-
Method Detail
-
getDebugMode
final Boolean getDebugMode()
If true, extra validations will be applied to ensure the view model is used correctly.
-
getStateStore
final MavericksStateStore<S> getStateStore()
The state store instance that will control the state of the ViewModel.
-
getCoroutineScope
final CoroutineScope getCoroutineScope()
The coroutine scope that will be provided to the view model.
-
getSubscriptionCoroutineContextOverride
final CoroutineContext getSubscriptionCoroutineContextOverride()
Provide a context that will be added to the coroutine scope when a subscription is registered (eg MavericksView.onEach).
By default subscriptions use MavericksView.subscriptionLifecycleOwner and LifecycleOwner.lifecycleScope to retrieve a coroutine scope to launch the subscription in.
-
onExecute
abstract <S extends MavericksState> MavericksBlockExecutions onExecute(MavericksViewModel<S> viewModel)
Called each time a MavericksRepository.execute function is invoked. This allows the execute function to be skipped, based on the returned MavericksBlockExecutions value.
This is intended to be used to allow the MavericksRepository to be mocked out for testing. Blocking calls to execute prevents long running asynchronous operations from changing the state later on when the calls complete.
Mocking out the state store cannot accomplish this on its own, because in some cases we may want the state store to initially be mocked, with state changes blocked, but later on we may want it to allow state changes.
This prevents the case of an executed async call from modifying state once the state stored is "enabled", even if the execute was performed when the state store was "disabled" and we didn't intend to allow operations to change the state.
-
-
-
-