Package 

Class BaseMvRxViewModel


  • 
    public abstract class BaseMvRxViewModel<S extends MavericksState>
    extends MavericksViewModel<S>
                        

    Base ViewModel implementation that all other ViewModels should extend.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final MavericksViewModelConfig<S> config
      private final Flow<S> stateFlow
      private final CoroutineScope viewModelScope
    • Method Summary

      Modifier and Type Method Description
      final MavericksViewModelConfig<S> getConfig()
      final Flow<S> getStateFlow()
      final CoroutineScope getViewModelScope()
      Unit onCleared()
      final <T extends Any> Disposable execute(Single<T> $self, Function2<S, Async<T>, S> stateReducer) Helper to map a Single to an Async property on the state object.
      final <T extends Any, V extends Any> Disposable execute(Single<T> $self, Function1<T, V> mapper, Function2<S, Async<V>, S> stateReducer) Helper to map a Single to an Async property on the state object.
      final <T extends Any> Disposable execute(Observable<T> $self, Function2<S, Async<T>, S> stateReducer) Helper to map an Observable to an Async property on the state object.
      final Disposable execute(Completable $self, Function2<S, Async<Unit>, S> stateReducer) Helper to map a Completable to an Async property on the state object.
      final <T extends Any, V extends Any> Disposable execute(Observable<T> $self, Function1<T, V> mapper, Function1<T, Object> successMetaData, Function2<S, Async<V>, S> stateReducer) Execute an Observable and wrap its progression with Async property reduced to the global state.
      final Unit logStateChanges() Output all state changes to logcat.
      final Disposable subscribe(LifecycleOwner owner, DeliveryMode deliveryMode, Function1<S, Unit> subscriber) Subscribe to state when this LifecycleOwner is started.
      • Methods inherited from class com.airbnb.mvrx.BaseMvRxViewModel

        awaitState, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BaseMvRxViewModel

        BaseMvRxViewModel(S initialState)
    • Method Detail

      • getConfig

         final MavericksViewModelConfig<S> getConfig()
      • execute

         final <T extends Any> Disposable execute(Single<T> $self, Function2<S, Async<T>, S> stateReducer)

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

      • execute

         final <T extends Any, V extends Any> Disposable execute(Single<T> $self, Function1<T, V> mapper, Function2<S, Async<V>, S> stateReducer)

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

        Parameters:
        mapper - A map converting the Single type to the desired Async type.
        stateReducer - A reducer that is applied to the current state and should return the new state.
      • execute

         final <T extends Any> Disposable execute(Observable<T> $self, Function2<S, Async<T>, S> stateReducer)

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

      • execute

         final Disposable execute(Completable $self, Function2<S, Async<Unit>, S> stateReducer)

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

      • execute

         final <T extends Any, V extends Any> Disposable execute(Observable<T> $self, Function1<T, V> mapper, Function1<T, Object> successMetaData, Function2<S, Async<V>, S> stateReducer)

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

        Parameters:
        mapper - A map converting the Observable type to the desired Async type.
        successMetaData - A map that provides metadata to set on the Success result.
        stateReducer - A reducer that is applied to the current state and should return the new state.