-
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>configprivate final Flow<S>stateFlowprivate final CoroutineScopeviewModelScope
-
Constructor Summary
Constructors Constructor Description BaseMvRxViewModel(S initialState)
-
Method Summary
Modifier and Type Method Description final MavericksViewModelConfig<S>getConfig()final Flow<S>getStateFlow()final CoroutineScopegetViewModelScope()UnitonCleared()final <T extends Any> Disposableexecute(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> Disposableexecute(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> Disposableexecute(Observable<T> $self, Function2<S, Async<T>, S> stateReducer)Helper to map an Observable to an Async property on the state object. final Disposableexecute(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> Disposableexecute(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 UnitlogStateChanges()Output all state changes to logcat. final Disposablesubscribe(LifecycleOwner owner, DeliveryMode deliveryMode, Function1<S, Unit> subscriber)Subscribe to state when this LifecycleOwner is started. -
-
Constructor Detail
-
BaseMvRxViewModel
BaseMvRxViewModel(S initialState)
-
-
Method Detail
-
getStateFlow
final Flow<S> getStateFlow()
-
getViewModelScope
final CoroutineScope getViewModelScope()
-
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.
-
logStateChanges
final Unit logStateChanges()
Output all state changes to logcat.
-
subscribe
@RestrictTo(value = {RestrictTo.Scope.LIBRARY}) final Disposable subscribe(LifecycleOwner owner, DeliveryMode deliveryMode, Function1<S, Unit> subscriber)
Subscribe to state when this LifecycleOwner is started.
-
-
-
-