MavericksView

interface MavericksView : LifecycleOwner

Functions

collectLatest
Link copied to clipboard
open fun <T> Flow<T>.collectLatest(deliveryMode: DeliveryMode, action: suspend (T) -> Unit): Job

Subscribes to the given Flow within the coroutine scope of the subscriptionLifecycleOwner, starting the flow only when the lifecycle is started, and executing with the coroutine context of Mavericks' subscriptionCoroutineContextOverride. This can be utilized to create customized subscriptions, for example, to drop the first element in the flow before continuing. This is intended to be used with viewmodel.stateflow.

getLifecycle
Link copied to clipboard
abstract fun getLifecycle(): Lifecycle
invalidate
Link copied to clipboard
abstract fun invalidate()

Override this to handle any state changes from MavericksViewModels created through MvRx Fragment delegates.

onAsync
Link copied to clipboard
open fun <S : MavericksState, T> MavericksViewModel<S>.onAsync(asyncProp: KProperty1<S, Async<T>>, deliveryMode: DeliveryMode = RedeliverOnStart, onFail: suspend (Throwable) -> Unit? = null, onSuccess: suspend (T) -> Unit? = null): Job

Subscribe to changes in an async property. There are optional parameters for onSuccess and onFail which automatically unwrap the value or error.

onEach
Link copied to clipboard
open fun <S : MavericksState> MavericksViewModel<S>.onEach(deliveryMode: DeliveryMode = RedeliverOnStart, action: suspend (S) -> Unit): Job

Subscribes to all state updates for the given viewModel.

open fun <S : MavericksState, A> MavericksViewModel<S>.onEach(prop1: KProperty1<S, A>, deliveryMode: DeliveryMode = RedeliverOnStart, action: suspend (A) -> Unit): Job

Subscribes to state changes for only a specific property and calls the action with only that single property.

open fun <S : MavericksState, A, B> MavericksViewModel<S>.onEach(prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, deliveryMode: DeliveryMode = RedeliverOnStart, action: suspend (A, B) -> Unit): Job

Subscribes to state changes for two properties.

open fun <S : MavericksState, A, B, C> MavericksViewModel<S>.onEach(prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, prop3: KProperty1<S, C>, deliveryMode: DeliveryMode = RedeliverOnStart, action: suspend (A, B, C) -> Unit): Job

Subscribes to state changes for three properties.

open fun <S : MavericksState, A, B, C, D> MavericksViewModel<S>.onEach(prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, prop3: KProperty1<S, C>, prop4: KProperty1<S, D>, deliveryMode: DeliveryMode = RedeliverOnStart, action: suspend (A, B, C, D) -> Unit): Job

Subscribes to state changes for four properties.

open fun <S : MavericksState, A, B, C, D, E> MavericksViewModel<S>.onEach(prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, prop3: KProperty1<S, C>, prop4: KProperty1<S, D>, prop5: KProperty1<S, E>, deliveryMode: DeliveryMode = RedeliverOnStart, action: suspend (A, B, C, D, E) -> Unit): Job

Subscribes to state changes for five properties.

open fun <S : MavericksState, A, B, C, D, E, F> MavericksViewModel<S>.onEach(prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, prop3: KProperty1<S, C>, prop4: KProperty1<S, D>, prop5: KProperty1<S, E>, prop6: KProperty1<S, F>, deliveryMode: DeliveryMode = RedeliverOnStart, action: suspend (A, B, C, D, E, F) -> Unit): Job

Subscribes to state changes for six properties.

open fun <S : MavericksState, A, B, C, D, E, F, G> MavericksViewModel<S>.onEach(prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, prop3: KProperty1<S, C>, prop4: KProperty1<S, D>, prop5: KProperty1<S, E>, prop6: KProperty1<S, F>, prop7: KProperty1<S, G>, deliveryMode: DeliveryMode = RedeliverOnStart, action: suspend (A, B, C, D, E, F, G) -> Unit): Job

Subscribes to state changes for seven properties.

postInvalidate
Link copied to clipboard
open fun postInvalidate()
uniqueOnly
Link copied to clipboard
open fun uniqueOnly(customId: String? = null): UniqueOnly

Return a UniqueOnly delivery mode with a unique id for this fragment. In rare circumstances, if you make two identical subscriptions with the same (or all) properties in this fragment, provide a customId to avoid collisions.

Properties

mavericksViewInternalViewModel
Link copied to clipboard
mvrxViewId
Link copied to clipboard
open val mvrxViewId: String

Override this to supply a globally unique id for this MvRxView. If your MavericksView is being recreated due to a lifecycle event (e.g. rotation) you should assign a consistent id. Likely this means you should save the id in onSaveInstance state. The viewId will not be accessed until a subscribe method is called. Accessing mvrxViewId before calling super.onCreate() will cause a crash.

subscriptionLifecycleOwner
Link copied to clipboard
open val subscriptionLifecycleOwner: LifecycleOwner

The LifecycleOwner to use when making new subscriptions. You may want to return different owners depending on what state your MavericksView is in.

Extensions

cancelPendingInvalidates
Link copied to clipboard
fun MavericksView.cancelPendingInvalidates()

If any callbacks to run MavericksView.invalidate have been posted with MavericksView.postInvalidate then this cancels them.