fragmentViewModel

inline fun <T : Fragment, MavericksView, VM : MavericksViewModel<S>, S : MavericksState> T.fragmentViewModel(viewModelClass: KClass<VM> = VM::class, crossinline keyFactory: () -> String = { viewModelClass.java.name }): MavericksDelegateProvider<T, VM>

Gets or creates a ViewModel scoped to this Fragment. You will get the same instance every time for this Fragment, even through rotation, or other configuration changes.

If the ViewModel has additional dependencies, implement MavericksViewModelFactory in its companion object. You will be given the initial state as well as a FragmentActivity with which you can access other dependencies to pass to the ViewModel's constructor.

Mavericks will also handle persistence across process restarts. Refer to PersistState for more info.

Use keyFactory if you have multiple ViewModels of the same class in the same scope.