-
public class MavericksViewModelConfigFactoryFactory for providing the MavericksViewModelConfig for each new ViewModel that is created.
An instance of this must be set on Mavericks.viewModelConfigFactory.
A custom subclass of this may be used to allow you to override buildConfig, but this should generally not be necessary.
-
-
Field Summary
Fields Modifier and Type Field Description private final BooleandebugModeprivate final CoroutineContextcontextOverrideprivate final CoroutineContextstoreContextOverrideprivate final CoroutineContextsubscriptionCoroutineContextOverride
-
Constructor Summary
Constructors Constructor Description MavericksViewModelConfigFactory(Context context, CoroutineContext contextOverride, CoroutineContext storeContextOverride)Sets debugMode depending on whether the app was built with the Debuggable flag enabled. MavericksViewModelConfigFactory(Boolean debugMode, CoroutineContext contextOverride, CoroutineContext storeContextOverride, CoroutineContext subscriptionCoroutineContextOverride)
-
Method Summary
Modifier and Type Method Description final BooleangetDebugMode()True if debug checks should be run. final CoroutineContextgetContextOverride()Provide a default context for viewModelScope. final CoroutineContextgetStoreContextOverride()Provide an additional context that will be used in the CoroutinesStateStore. final CoroutineContextgetSubscriptionCoroutineContextOverride()Provide a context that will be added to the coroutine scope when a subscription is registered (eg MavericksView.onEach). CoroutineScopecoroutineScope()<S extends MavericksState> MavericksViewModelConfig<S>buildConfig(MavericksViewModel<S> viewModel, S initialState)Create a new MavericksViewModelConfig for the given viewmodel. final UnitaddOnConfigProvidedListener(Function2<MavericksViewModel<?>, MavericksViewModelConfig<?>, Unit> callback)Add a listener that will be called every time a MavericksViewModelConfig is created for a new view model. final UnitremoveOnConfigProvidedListener(Function2<MavericksViewModel<?>, MavericksViewModelConfig<?>, Unit> callback)-
-
Constructor Detail
-
MavericksViewModelConfigFactory
MavericksViewModelConfigFactory(Context context, CoroutineContext contextOverride, CoroutineContext storeContextOverride)
Sets debugMode depending on whether the app was built with the Debuggable flag enabled.
-
MavericksViewModelConfigFactory
MavericksViewModelConfigFactory(Boolean debugMode, CoroutineContext contextOverride, CoroutineContext storeContextOverride, CoroutineContext subscriptionCoroutineContextOverride)
-
-
Method Detail
-
getDebugMode
final Boolean getDebugMode()
True if debug checks should be run. Should be false for production builds. When true, certain validations are applied to the ViewModel. These can be slow and should not be used in production! However, they do help to catch common issues so it is highly recommended that you enable debug when applicable.
-
getContextOverride
final CoroutineContext getContextOverride()
Provide a default context for viewModelScope. It will be added after SupervisorJob and Dispatchers.Main.immediate.
-
getStoreContextOverride
final CoroutineContext getStoreContextOverride()
Provide an additional context that will be used in the CoroutinesStateStore. All withState/setState calls will be executed in this context. By default these calls are executed with a shared thread pool dispatcher that is private to CoroutinesStateStore
-
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.
-
coroutineScope
CoroutineScope coroutineScope()
-
buildConfig
<S extends MavericksState> MavericksViewModelConfig<S> buildConfig(MavericksViewModel<S> viewModel, S initialState)
Create a new MavericksViewModelConfig for the given viewmodel. This can be overridden to customize the config.
-
addOnConfigProvidedListener
final Unit addOnConfigProvidedListener(Function2<MavericksViewModel<?>, MavericksViewModelConfig<?>, Unit> callback)
Add a listener that will be called every time a MavericksViewModelConfig is created for a new view model. This will happen each time a new ViewModel is created.
The callback includes a reference to the ViewModel that the config was created for, as well as the configuration itself.
-
removeOnConfigProvidedListener
final Unit removeOnConfigProvidedListener(Function2<MavericksViewModel<?>, MavericksViewModelConfig<?>, Unit> callback)
-
-
-
-