Package com. airbnb. mvrx
Types
The ViewModelContext for a ViewModel created with an activity scope (val viewModel by activityViewModel<MyViewModel>). Although a fragment reference is available when an activity scoped ViewModel is first created, during process restoration, activity scoped ViewModels will be created without a fragment reference, so it is only safe to reference the activity.
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).
Defines what updates a subscription should receive. See: RedeliverOnStart, UniqueOnly.
The ViewModelContext for a ViewModel created with a fragment scope (val viewModel by fragmentViewModel<MyViewModel>).
Helper interface for using Async in a when clause for handling both Uninitialized and Loading.
This was copied from SynchronizedLazyImpl but modified to automatically initialize in ON_CREATE.
Interface that has to be implemented by all Kotlin data classes that will be used as state.
All Mavericks ViewModels must extend this class. In Mavericks, ViewModels are generic on a single state class. The ViewModel owns all state modifications via setState and other classes may observe the state.
Provides configuration for a MavericksViewModel.
Factory for providing the MavericksViewModelConfig for each new ViewModel that is created.
Implement this on your ViewModel's companion object for hooks into state creation and ViewModel creation. For example, if you need access to the fragment or activity owner for dependency injection.
Helper 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.
Annotate a field in your MvRxViewModel state with PersistState to have it automatically persisted when Android kills your process to free up memory. MvRx will automatically recreate your ViewModel when the process restarts with these fields saved.
The subscription will receive the most recent state update when transitioning from locked to unlocked states (stopped -> started), even if the state has not changed while locked.
A MavericksStateStore which ignores standard calls to set. Instead it can be scripted via calls to next. This is intended to be used for tests only, and in particular UI tests where you wish to test how your UI code reacts to different ViewModel states. This is not as useful for unit testing your view model, as business logic in state reducers will not be used.
The subscription will receive the most recent state update when transitioning from locked to unlocked states (stopped -> started), only if the state has changed while locked. This will include the initial state as a state update.
Creation context for the ViewModel. Includes the ViewModel store owner (either an activity or fragment), and fragment arguments set via Mavericks.KEY_ARG.
This is invoked each time a Fragment accesses a ViewModel via the MvRx extension functions (eg fragmentViewModel, activityViewModel, existingViewModel).
Functions
For internal use only. Public for inline.
fragmentViewModel except scoped to the current Activity. Use this to share state between different Fragments.
Helper to handle pagination. Use this when you want to append a list of results at a given offset. This is safer than just appending blindly to a list because it guarantees that the data gets added at the offset it was requested at.
Wraps StrictMode.ThreadPolicy into ThreadContextElement. The resulting ThreadContextElement maintains the given policy for coroutine regardless of the actual thread its is resumed on.
Takes anything that is Parcelable and creates a Mavericks Fragment argument Bundle.
Takes anything that is serializable and creates a Mavericks Fragment argument Bundle.
Ensures that the state class is immutable. NOTE: Kotlin collections immutability is a compile-time check only and the underlying classes are mutable so it is impossible to detect them here. Kotlin mutability: https://stackoverflow.com/a/33732403/715633
If any callbacks to run MavericksView.invalidate have been posted with MavericksView.postInvalidate then this cancels them.
activityViewModel except it will throw IllegalStateException if the ViewModel doesn't already exist. Use this for screens in the middle of a flow that cannot reasonably be an entry point to the flow.
Emits values from the source flow only when the owner is started. When the owner transitions to started, the most recent value will be emitted.
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.
Gets or creates a ViewModel scoped to a parent fragment. This delegate will walk up the parentFragment hierarchy until it finds a Fragment that can provide the correct ViewModel. If no parent fragments can provide the ViewModel, a new one will be created in top-most parent Fragment.
Iterates through all member properties annotated with PersistState and parcels them into a bundle that can be saved with savedInstanceState.
Updates the initial state object given state persisted with PersistState in a Bundle.
Gets or creates a ViewModel scoped to a target fragment. Throws IllegalStateException if there is no target fragment.
Gets or creates a ViewModel scoped to the current activity. This is similar to fragmentViewModel and actvityViewModel but used when a view model is accessed directly from an activity itself.
Accesses ViewModel state from a single ViewModel synchronously and returns the result of the block.
Accesses ViewModel state from two ViewModels synchronously and returns the result of the block.
Accesses ViewModel state from three ViewModels synchronously and returns the result of the block.
Accesses ViewModel state from four ViewModels synchronously and returns the result of the block.
Accesses ViewModel state from five ViewModels synchronously and returns the result of the block.