get

fun <VM : MavericksViewModel<S>, S : MavericksState> get(viewModelClass: Class<out VM>, stateClass: Class<out S>, viewModelContext: ViewModelContext, key: String = viewModelClass.name, forExistingViewModel: Boolean = false, initialStateFactory: MavericksStateFactory<VM, S> = RealMavericksStateFactory()): VM

MvRx specific ViewModelProvider used for creating a BaseMavericksViewModel scoped to either a Fragment or ComponentActivity. If this is in a Fragment, it cannot be called before the Fragment has been added to an Activity or wrapped in a Lazy call.

Parameters

viewModelClass

The class of the ViewModel you would like an instance of.

stateClass

The class of the State used by the ViewModel.

viewModelContext

The ViewModelContext which contains arguments and the owner of the ViewModel. Either ActivityViewModelContext or FragmentViewModelContext.

key

An optional key for the ViewModel in the store. This is optional but should be used if you have multiple of the same ViewModel class in the same scope.

forExistingViewModel

If true the viewModel should already have been created. If it has not been created already, a ViewModelDoesNotExistException will be thrown

initialStateFactory

A way to specify how to create the initial state, can be mocked out for testing.