//reactivestate/com.ensody.reactivestate.android
Package-level declarations¶
Types¶
Name | Summary |
---|---|
BuildOnViewModelContext | [android] class BuildOnViewModelContext(val scope: CoroutineScope, val stateFlowStore: StateFlowStore) Build context for buildOnViewModel. |
LifecycleCoroutineLauncher | [android] class LifecycleCoroutineLauncher(val owner: LifecycleOwner) : SimpleCoroutineLauncher A SimpleCoroutineLauncher that launches coroutines in the STARTED state. |
SavedStateHandleStore | [android] class SavedStateHandleStore(scope: CoroutineScope?, savedStateHandle: SavedStateHandle) : StateFlowStore A StateFlowStore that wraps a SavedStateHandle. |
WrapperViewModel | [android] class WrapperViewModel(val stateFlowStore: StateFlowStore) : ViewModel The wrapper ViewModel used by buildOnViewModel. |
Properties¶
Name | Summary |
---|---|
savedInstanceState | [android] val ComponentActivity.savedInstanceState: StateFlowStore val Fragment.savedInstanceState: StateFlowStore Returns a StateFlowStore where you can put your saved instance state. |
Functions¶
Name | Summary |
---|---|
activityStateFlowViewModel | [android] inline fun <T : ViewModel> Fragment.activityStateFlowViewModel(crossinline provider: (handle: SavedStateHandleStore) -> T): Lazy<T> Creates a ViewModel with a SavedStateHandleStore, scoped to the Activity . |
activityStateViewModel | [android] inline fun <T : ViewModel> Fragment.activityStateViewModel(crossinline provider: (handle: SavedStateHandle) -> T): Lazy<T> Creates a ViewModel with a SavedStateHandle , scoped to the Activity . |
activityViewModel | [android] inline fun <T : ViewModel> Fragment.activityViewModel(crossinline provider: () -> T): Lazy<T> Creates a ViewModel scoped to the Activity . |
attachLazyReactiveState | [android] fun <E : ErrorEvents> Lazy<ReactiveState<E>>.attachLazyReactiveState(handler: E?, owner: LifecycleOwner) |
autoRun | [android] fun LifecycleOwner.autoRun(launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else LifecycleCoroutineLauncher(this), onChange: AutoRunOnChangeCallback<Unit>? = null, observer: AutoRunCallback<Unit>): AutoRunner<Unit> Watches observables for changes. Often useful to keep things in sync (e.g. ViewModel -> UI). [android] fun ViewModel.autoRun(launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else SimpleCoroutineLauncher(viewModelScope), onChange: AutoRunOnChangeCallback<Unit>? = null, observer: AutoRunCallback<Unit>): AutoRunner<Unit> Watches observables for changes. Often useful to keep things in sync. |
buildOnViewModel | [android] inline fun <T : Any> ComponentActivity.buildOnViewModel(crossinline provider: BuildOnViewModelContext.() -> T): Lazy<T> Creates an object living on a wrapper ViewModel . This allows for building multiplatform ViewModels.[android] inline fun <T : Any> Fragment.buildOnViewModel(crossinline provider: BuildOnViewModelContext.() -> T): Lazy<T> Creates an object living on a wrapper ViewModel. This allows for building multiplatform ViewModels. [android] fun <T : Any> Lazy<WrapperViewModel>.buildOnViewModel(klass: KClass<T>, caster: (Any?) -> T?, provider: BuildOnViewModelContext.() -> T): Lazy<T> Used internally by buildOnViewModel. |
buildViewModel | [android] inline fun <T : ViewModel> ComponentActivity.buildViewModel(crossinline provider: () -> T): Lazy<T> inline fun <T : ViewModel> Fragment.buildViewModel(crossinline provider: () -> T): Lazy<T> Creates a ViewModel . |
coAutoRun | [android] fun ViewModel.coAutoRun(launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else SimpleCoroutineLauncher(viewModelScope), onChange: CoAutoRunOnChangeCallback<Unit>? = null, observer: CoAutoRunCallback<Unit>): CoAutoRunner<Unit> Watches observables for changes. Often useful to keep things in sync. [android] fun LifecycleOwner.coAutoRun(launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else LifecycleCoroutineLauncher(this), onChange: CoAutoRunOnChangeCallback<Unit>? = null, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableValueFlow<Int>? = if (this is CoroutineLauncher) launcher.loading else null, observer: AutoRunCallback<Unit>): CoAutoRunner<Unit> Watches observables for changes. Often useful to keep things in sync (e.g. ViewModel -> UI). |
derived | [android] fun <T> LifecycleOwner.derived(launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else LifecycleCoroutineLauncher(this), synchronous: Boolean = true, observer: AutoRunCallback<T>): StateFlow<T> fun <T> ViewModel.derived(launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else SimpleCoroutineLauncher(viewModelScope), synchronous: Boolean = true, observer: AutoRunCallback<T>): StateFlow<T> Creates a StateFlow that computes its value based on other StateFlows via an autoRun block. [android] fun <T> LifecycleOwner.derived(initial: T, started: SharingStarted = SharingStarted.Eagerly, launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else LifecycleCoroutineLauncher(this), flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableValueFlow<Int>? = if (this is CoroutineLauncher) launcher.loading else null, observer: CoAutoRunCallback<T>): StateFlow<T> fun <T> ViewModel.derived(initial: T, started: SharingStarted = SharingStarted.Eagerly, launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else SimpleCoroutineLauncher(viewModelScope), flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableValueFlow<Int>? = if (this is CoroutineLauncher) launcher.loading else null, observer: CoAutoRunCallback<T>): StateFlow<T> Creates a StateFlow that computes its value based on other StateFlows via a suspendable coAutoRun block. |
handleEvents | [android] fun <T : ErrorEvents> EventNotifier<T>.handleEvents(handler: T, owner: LifecycleOwner) Consumes and handles EventNotifier’s events on the given handler, but only when owner is in >=STARTED state. |
launchOnceStateAtLeast | [android] fun LifecycleOwner.launchOnceStateAtLeast(state: Lifecycle.State, context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, cancelWhenBelow: Boolean = true, block: suspend CoroutineScope.() -> Unit): Job Waits until the lifecycle reaches the given state and then launches a coroutine with the given block. |
LifecycleStateFlow | [android] fun LifecycleStateFlow(lifecycle: Lifecycle): StateFlow<Lifecycle.State> A StateFlow that tracks the current Lifecycle.State. |
onceStateAtLeast | [android] suspend fun <T> LifecycleOwner.onceStateAtLeast(state: Lifecycle.State, cancelWhenBelow: Boolean, block: suspend () -> T): T Waits until the lifecycle reaches the given state and then runs block. |
onCreate | [android] fun LifecycleOwner.onCreate(block: () -> Unit): Disposable Runs the given block on every Lifecycle.Event.ON_CREATE . |
onCreateOnce | [android] fun LifecycleOwner.onCreateOnce(block: () -> Unit): Disposable Runs the given block once on the next Lifecycle.Event.ON_DESTROY . |
onCreateView | [android] fun Fragment.onCreateView(block: () -> Unit): Disposable Runs the given block on every Fragment.onCreateView (actually onViewStateRestored ). |
onCreateViewOnce | [android] fun Fragment.onCreateViewOnce(block: () -> Unit): Disposable Runs the given block once on the next Fragment.onCreateView (actually onViewStateRestored ). |
onDestroy | [android] fun LifecycleOwner.onDestroy(block: () -> Unit): Disposable Runs the given block on every Lifecycle.Event.ON_DESTROY . |
onDestroyOnce | [android] fun LifecycleOwner.onDestroyOnce(block: () -> Unit): Disposable Runs the given block once on the next Lifecycle.Event.ON_DESTROY . |
onDestroyView | [android] fun Fragment.onDestroyView(block: () -> Unit): Disposable Runs the given block on every Fragment.onDestroyView . |
onDestroyViewOnce | [android] fun Fragment.onDestroyViewOnce(block: () -> Unit): Disposable Runs the given block once on the next Fragment.onDestroyView . |
onPause | [android] fun LifecycleOwner.onPause(block: () -> Unit): Disposable Runs the given block on every Lifecycle.Event.ON_PAUSE . |
onPauseOnce | [android] fun LifecycleOwner.onPauseOnce(block: () -> Unit): Disposable Runs the given block once on the next Lifecycle.Event.ON_PAUSE . |
onResume | [android] fun LifecycleOwner.onResume(block: () -> Unit): Disposable Runs the given block on every Lifecycle.Event.ON_RESUME . |
onResumeOnce | [android] fun LifecycleOwner.onResumeOnce(block: () -> Unit): Disposable Runs the given block once on the next Lifecycle.Event.ON_RESUME . |
onStart | [android] fun LifecycleOwner.onStart(block: () -> Unit): Disposable Runs the given block on every Lifecycle.Event.ON_START . |
onStartOnce | [android] fun LifecycleOwner.onStartOnce(block: () -> Unit): Disposable Runs the given block once on the next Lifecycle.Event.ON_START . |
onStop | [android] fun LifecycleOwner.onStop(block: () -> Unit): Disposable Runs the given block on every Lifecycle.Event.ON_STOP . |
onStopOnce | [android] fun LifecycleOwner.onStopOnce(block: () -> Unit): Disposable Runs the given block once on the next Lifecycle.Event.ON_STOP . |
reactiveState | [android] inline fun <E : ErrorEvents, T : ReactiveState<E>> ComponentActivity.reactiveState(crossinline provider: BuildOnViewModelContext.() -> T): Lazy<T> inline fun <E : ErrorEvents, T : ReactiveState<E>> Fragment.reactiveState(crossinline provider: BuildOnViewModelContext.() -> T): Lazy<T> Creates a multiplatform ReactiveState ViewModel and observes its ReactiveState.eventNotifier. |
savedInstanceState | [android] fun <T> ComponentActivity.savedInstanceState(default: T): ReadOnlyProperty<Any?, MutableValueFlow<T>> fun <T> Fragment.savedInstanceState(default: T): ReadOnlyProperty<Any?, MutableValueFlow<T>> Returns a StateFlowStore where you can put your saved instance state. |
stateFlowStore | [android] fun SavedStateHandle.stateFlowStore(scope: CoroutineScope): SavedStateHandleStore |
stateFlowViewModel | [android] inline fun <T : ViewModel> ComponentActivity.stateFlowViewModel(crossinline provider: (handle: SavedStateHandleStore) -> T): Lazy<T> inline fun <T : ViewModel> Fragment.stateFlowViewModel(crossinline provider: (store: SavedStateHandleStore) -> T): Lazy<T> Creates a ViewModel with a SavedStateHandleStore. |
stateViewModel | [android] inline fun <T : ViewModel> ComponentActivity.stateViewModel(crossinline provider: (handle: SavedStateHandle) -> T): Lazy<T> inline fun <T : ViewModel> Fragment.stateViewModel(crossinline provider: (handle: SavedStateHandle) -> T): Lazy<T> Creates a ViewModel with a SavedStateHandle . |