mvrx-rxjava2 / com.airbnb.mvrx / BaseMvRxViewModel

BaseMvRxViewModel

abstract class BaseMvRxViewModel<S : MavericksState> : MavericksViewModel<S>

Base ViewModel implementation that all other ViewModels should extend.

Constructors

<init>

BaseMvRxViewModel(initialState: S)

Base ViewModel implementation that all other ViewModels should extend.

Functions

asyncSubscribe

fun <T> asyncSubscribe(asyncProp: KProperty1<S, Async<T>>, onFail: ((Throwable) -> Unit)? = null, onSuccess: ((T) -> Unit)? = null): Disposable

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

fun <T, S : MavericksState> asyncSubscribe(viewModel: BaseMvRxViewModel<S>, asyncProp: KProperty1<S, Async<T>>, onFail: ((Throwable) -> Unit)? = null, onSuccess: ((T) -> Unit)? = null): Unit

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

disposeOnClear

fun Disposable.disposeOnClear(): Disposable

execute

fun <T> Single<T>.execute(stateReducer: S.(Async<T>) -> S): Disposable
fun <T, V> Single<T>.execute(mapper: (T) -> V, stateReducer: S.(Async<V>) -> S): Disposable

Helper to map a Single to an Async property on the state object.

fun <T> Observable<T>.execute(stateReducer: S.(Async<T>) -> S): Disposable

Helper to map an Observable to an Async property on the state object.

fun Completable.execute(stateReducer: S.(Async<Unit>) -> S): Disposable

Helper to map a Completable to an Async property on the state object.

fun <T, V> Observable<T>.execute(mapper: (T) -> V, successMetaData: ((T) -> Any)? = null, stateReducer: S.(Async<V>) -> S): Disposable

Execute an Observable and wrap its progression with Async property reduced to the global state.

logStateChanges

fun logStateChanges(): Unit

Output all state changes to logcat.

onCleared

open fun onCleared(): Unit

selectSubscribe

fun <A> selectSubscribe(prop1: KProperty1<S, A>, subscriber: (A) -> Unit): Disposable

Subscribe to state changes for only a single property.

fun <A, S : MavericksState> selectSubscribe(viewModel: BaseMvRxViewModel<S>, prop1: KProperty1<S, A>, subscriber: (A) -> Unit): Unit

Subscribe to state changes for only a single property in a different ViewModel.

fun <A, B> selectSubscribe(prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, subscriber: (A, B) -> Unit): Disposable

Subscribe to state changes for two properties.

fun <A, B, S : MavericksState> selectSubscribe(viewModel: BaseMvRxViewModel<S>, prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, subscriber: (A, B) -> Unit): Unit

Subscribe to state changes for two properties in a different ViewModel.

fun <A, B, C> selectSubscribe(prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, prop3: KProperty1<S, C>, subscriber: (A, B, C) -> Unit): Disposable

Subscribe to state changes for three properties.

fun <A, B, C, S : MavericksState> selectSubscribe(viewModel: BaseMvRxViewModel<S>, prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, prop3: KProperty1<S, C>, subscriber: (A, B, C) -> Unit): Unit

Subscribe to state changes for three properties in a different ViewModel.

fun <A, B, C, D> selectSubscribe(prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, prop3: KProperty1<S, C>, prop4: KProperty1<S, D>, subscriber: (A, B, C, D) -> Unit): Disposable

Subscribe to state changes for four properties.

fun <A, B, C, D, S : MavericksState> selectSubscribe(viewModel: BaseMvRxViewModel<S>, prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, prop3: KProperty1<S, C>, prop4: KProperty1<S, D>, subscriber: (A, B, C, D) -> Unit): Unit

Subscribe to state changes for four properties in a different ViewModel.

fun <A, B, C, D, E> selectSubscribe(prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, prop3: KProperty1<S, C>, prop4: KProperty1<S, D>, prop5: KProperty1<S, E>, subscriber: (A, B, C, D, E) -> Unit): Disposable

Subscribe to state changes for five properties.

fun <A, B, C, D, E, S : MavericksState> selectSubscribe(viewModel: BaseMvRxViewModel<S>, prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, prop3: KProperty1<S, C>, prop4: KProperty1<S, D>, prop5: KProperty1<S, E>, subscriber: (A, B, C, D, E) -> Unit): Unit

Subscribe to state changes for five properties in a different ViewModel.

fun <A, B, C, D, E, F> selectSubscribe(prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, prop3: KProperty1<S, C>, prop4: KProperty1<S, D>, prop5: KProperty1<S, E>, prop6: KProperty1<S, F>, subscriber: (A, B, C, D, E, F) -> Unit): Disposable

Subscribe to state changes for six properties.

fun <A, B, C, D, E, F, S : MavericksState> selectSubscribe(viewModel: BaseMvRxViewModel<S>, prop1: KProperty1<S, A>, prop2: KProperty1<S, B>, prop3: KProperty1<S, C>, prop4: KProperty1<S, D>, prop5: KProperty1<S, E>, prop6: KProperty1<S, F>, subscriber: (A, B, C, D, E, F) -> Unit): Unit

Subscribe to state changes for six properties in a different ViewModel.

fun <A, B, C, D, E, F, G> selectSubscribe(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>, subscriber: (A, B, C, D, E, F, G) -> Unit): Disposable

Subscribe to state changes for seven properties.

fun <A, B, C, D, E, F, G, S : MavericksState> selectSubscribe(viewModel: BaseMvRxViewModel<S>, 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>, subscriber: (A, B, C, D, E, F, G) -> Unit): Unit

Subscribe to state changes for seven properties in a different ViewModel.

subscribe

fun subscribe(subscriber: (S) -> Unit): Disposable

For ViewModels that want to subscribe to itself.

fun subscribe(owner: LifecycleOwner, deliveryMode: DeliveryMode = RedeliverOnStart, subscriber: (S) -> Unit): Disposable

Subscribe to state when this LifecycleOwner is started.

fun <S : MavericksState> subscribe(viewModel: BaseMvRxViewModel<S>, subscriber: (S) -> Unit): Unit

For ViewModels that want to subscribe to another ViewModel.