MavericksViewModelConfigFactory

open class MavericksViewModelConfigFactory(debugMode: Boolean, contextOverride: CoroutineContext, storeContextOverride: CoroutineContext, subscriptionCoroutineContextOverride: CoroutineContext)

Factory 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.

Constructors

MavericksViewModelConfigFactory
Link copied to clipboard
fun MavericksViewModelConfigFactory(context: Context, contextOverride: CoroutineContext = EmptyCoroutineContext, storeContextOverride: CoroutineContext = EmptyCoroutineContext)

Sets debugMode depending on whether the app was built with the Debuggable flag enabled.

MavericksViewModelConfigFactory
Link copied to clipboard
fun MavericksViewModelConfigFactory(debugMode: Boolean, contextOverride: CoroutineContext = EmptyCoroutineContext, storeContextOverride: CoroutineContext = EmptyCoroutineContext, subscriptionCoroutineContextOverride: CoroutineContext = EmptyCoroutineContext)

Functions

addOnConfigProvidedListener
Link copied to clipboard
fun addOnConfigProvidedListener(callback: (MavericksViewModel<*>, MavericksViewModelConfig<*>) -> Unit)

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.

buildConfig
Link copied to clipboard
open fun <S : MavericksState> buildConfig(viewModel: MavericksViewModel<S>, initialState: S): MavericksViewModelConfig<S>

Create a new MavericksViewModelConfig for the given viewmodel. This can be overridden to customize the config.

coroutineScope
Link copied to clipboard
open fun coroutineScope(): CoroutineScope
removeOnConfigProvidedListener
Link copied to clipboard
fun removeOnConfigProvidedListener(callback: (MavericksViewModel<*>, MavericksViewModelConfig<*>) -> Unit)

Properties

contextOverride
Link copied to clipboard
val contextOverride: CoroutineContext

Provide a default context for viewModelScope. It will be added after SupervisorJob and Dispatchers.Main.immediate.

debugMode
Link copied to clipboard
val debugMode: Boolean

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.

storeContextOverride
Link copied to clipboard
val storeContextOverride: CoroutineContext

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

subscriptionCoroutineContextOverride
Link copied to clipboard

Provide a context that will be added to the coroutine scope when a subscription is registered (eg MavericksView.onEach).