-
public class MavericksViewModelProviderHelper ViewModelProvider that has a single method for taking either a Fragment or ComponentActivity instead of two separate ones. The logic for providing the correct scope is inside the method.
-
-
Field Summary
Fields Modifier and Type Field Description public final static MavericksViewModelProviderINSTANCE
-
Method Summary
Modifier and Type Method Description final <VM extends MavericksViewModel<S>, S extends MavericksState> VMget(Class<out VM> viewModelClass, Class<out S> stateClass, ViewModelContext viewModelContext, String key, Boolean forExistingViewModel, MavericksStateFactory<VM, S> initialStateFactory)Mavericks specific ViewModelProvider used for creating a BaseMavericksViewModel scoped to either a Fragment or ComponentActivity. -
-
Method Detail
-
get
final <VM extends MavericksViewModel<S>, S extends MavericksState> VM get(Class<out VM> viewModelClass, Class<out S> stateClass, ViewModelContext viewModelContext, String key, Boolean forExistingViewModel, MavericksStateFactory<VM, S> initialStateFactory)
Mavericks 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.key- An optional key for the ViewModel in the store.forExistingViewModel- If true the viewModel should already have been created.initialStateFactory- A way to specify how to create the initial state, can be mocked out for testing.
-
-
-
-