-
- All Implemented Interfaces:
-
com.airbnb.mvrx.ViewModelDelegateFactory
public final class DefaultViewModelDelegateFactory implements ViewModelDelegateFactory
Creates ViewModels that are wrapped with a lifecycleAwareLazy so that the ViewModel is automatically created when the Fragment is started (if it is not accessed before then).
ViewModels are created with a RealMavericksStateFactory.
The Fragment is subscribed to all changes to the ViewModel, so that MavericksView.postInvalidate is called on each State change. This allows the Fragment view to be automatically invalidated, only while the Fragment is in the STARTED lifecycle state.
-
-
Constructor Summary
Constructors Constructor Description DefaultViewModelDelegateFactory()
-
Method Summary
Modifier and Type Method Description <S extends MavericksState, T extends Fragment, MavericksView, VM extends MavericksViewModel<S>> Lazy<VM>createLazyViewModel(T fragment, KProperty<?> viewModelProperty, KClass<VM> viewModelClass, Function0<String> keyFactory, KClass<S> stateClass, Boolean existingViewModel, Function1<MavericksStateFactory<VM, S>, VM> viewModelProvider)Create a Lazy ViewModel for the given Fragment. -
-
Method Detail
-
createLazyViewModel
<S extends MavericksState, T extends Fragment, MavericksView, VM extends MavericksViewModel<S>> Lazy<VM> createLazyViewModel(T fragment, KProperty<?> viewModelProperty, KClass<VM> viewModelClass, Function0<String> keyFactory, KClass<S> stateClass, Boolean existingViewModel, Function1<MavericksStateFactory<VM, S>, VM> viewModelProvider)
Create a Lazy ViewModel for the given Fragment.
- Parameters:
existingViewModel- If true the view model is expected to already exist, so a new one should not need to be created.viewModelProvider- This function should be used to actually do the work of creating the viewmodel.
-
-
-
-