BaseCrViewModel

abstract class BaseCrViewModel<S : ViewState> : BaseViewModel<S> , CoroutineScopeOwner

Base ViewModel class prepared for providing data to UI through LiveData and obtaining data from Stores (Repositories) by executing Coroutine based use cases like UseCase and FlowUseCase.

Constructors

Link copied to clipboard
fun BaseCrViewModel()

Functions

Link copied to clipboard
fun clear()
Link copied to clipboard
open fun defaultErrorHandler(exception: Throwable)

This method is called when coroutine launched with launchWithHandler throws an exception and this exception isn't CancellationException. By default, it rethrows this exception.

Link copied to clipboard
open fun <T> FlowUseCase<Unit, T>.execute(config: CoroutineScopeOwner.FlowUseCaseConfig.Builder<T>.() -> Unit)

open suspend fun <T> UseCase<Unit, T>.execute(cancelPrevious: Boolean = true): Result<T>

Synchronously executes use case and saves it's Deferred. By default all previous pending executions are canceled, this can be changed by the cancelPrevious. This version is used for use cases without initial arguments.

open fun <T> UseCase<Unit, T>.execute(config: CoroutineScopeOwner.UseCaseConfig.Builder<T>.() -> Unit)

Asynchronously executes use case and saves it's Deferred. By default all previous pending executions are canceled, this can be changed by the config. This version is used for use cases without initial arguments.

open fun <ARGS, T> FlowUseCase<ARGS, T>.execute(args: ARGS, config: CoroutineScopeOwner.FlowUseCaseConfig.Builder<T>.() -> Unit)

Asynchronously executes use case and consumes data from flow on UI thread. By default all previous pending executions are canceled, this can be changed by config. When suspend function in use case finishes, onComplete is called on UI thread. This version is gets initial arguments by args.

open suspend fun <ARGS, T> UseCase<ARGS, T>.execute(args: ARGS, cancelPrevious: Boolean = true): Result<T>

Synchronously executes use case and saves it's Deferred. By default all previous pending executions are canceled, this can be changed by the cancelPrevious. This version gets initial arguments by args.

open fun <ARGS, T> UseCase<ARGS, T>.execute(args: ARGS, config: CoroutineScopeOwner.UseCaseConfig.Builder<T>.() -> Unit)

Asynchronously executes use case and saves it's Deferred. By default all previous pending executions are canceled, this can be changed by the config. This version gets initial arguments by args.

Link copied to clipboard
open fun <T : Any> getTag(p0: String): T
Link copied to clipboard
open fun getWorkerDispatcher(): CoroutineDispatcher

Provides Dispatcher for background tasks. This may be overridden for testing purposes

Link copied to clipboard
open fun launchWithHandler(block: suspend CoroutineScope.() -> Unit)

Launch suspend block in coroutineScope. Encapsulates this call with try catch block and when an exception is thrown then it is logged in UseCaseErrorHandler.globalOnErrorLogger and handled by defaultErrorHandler.

Link copied to clipboard
fun observeEvent(lifecycleOwner: LifecycleOwner, eventClass: KClass<out Event<S>>, observer: (Event<S>) -> Unit)
Link copied to clipboard
fun <T> LiveData<T>.observeWithoutOwner(callback: (T) -> Unit)
fun <T : Any> DefaultValueLiveData<T>.observeWithoutOwner(callback: (T) -> Unit)
fun <T : Any> DefaultValueMediatorLiveData<T>.observeWithoutOwner(callback: (T) -> Unit)
Link copied to clipboard
open override fun onCreate(@NonNull p0: LifecycleOwner)
Link copied to clipboard
open override fun onDestroy(@NonNull p0: LifecycleOwner)
Link copied to clipboard
open override fun onPause(@NonNull p0: LifecycleOwner)
Link copied to clipboard
open override fun onResume(@NonNull p0: LifecycleOwner)
Link copied to clipboard
open fun onStart()
open override fun onStart(owner: LifecycleOwner)
Link copied to clipboard
open override fun onStop(@NonNull p0: LifecycleOwner)
Link copied to clipboard
fun sendEvent(event: Event<S>)
Link copied to clipboard
open fun <T : Any> setTagIfAbsent(p0: String, p1: T): T

Properties

Link copied to clipboard
open override val coroutineScope: CoroutineScope

CoroutineScope scope used to execute coroutine based use cases. It is your responsibility to cancel it when all running tasks should be stopped

Link copied to clipboard
var internalSavedStateHandle: SavedStateHandle?
Link copied to clipboard
val requireSavedStateHandle: SavedStateHandle
Link copied to clipboard
abstract val viewState: S