container

fun <STATE : Any, SIDE_EFFECT : Any> ViewModel.container(initialState: STATE, settings: Container.Settings = Container.Settings(), onCreate: (STATE) -> Unit? = null): Container<STATE, SIDE_EFFECT>

Creates a container scoped with ViewModelScope.

Return

A Container implementation

Parameters

initialState

The initial state of the container.

settings

The Settings to set the container up with.

onCreate

The lambda to execute when the container is created. By default it is executed in a lazy manner after the container has been interacted with in any way.

fun <STATE : Parcelable, SIDE_EFFECT : Any> ViewModel.container(initialState: STATE, savedStateHandle: SavedStateHandle, settings: Container.Settings = Container.Settings(idlingRegistry = AndroidIdlingResource()), onCreate: (STATE) -> Unit? = null): Container<STATE, SIDE_EFFECT>

Creates a container scoped with ViewModelScope and allows you to used the Android ViewModel's saved state support.

Provide a SavedStateHandle in order for your Parcelable state to be automatically saved as you use the container.

Return

A Container implementation

Parameters

initialState

The initial state of the container.

savedStateHandle

The SavedStateHandle corresponding to this host. Typically retrieved from the containing ViewModel

settings

The Settings to set the container up with.

onCreate

The lambda to execute when the container is created, parameter is false, or recreated, parameter is true. By default it is executed in a lazy manner after the container has been interacted with in any way.