Package-level declarations

Types

Link copied to clipboard
class BuildOnViewModelContext(val scope: CoroutineScope, val stateFlowStore: StateFlowStore)

Build context for buildOnViewModel.

Link copied to clipboard

A SimpleCoroutineLauncher that launches coroutines in the STARTED state.

Link copied to clipboard
class SavedStateHandleStore(scope: CoroutineScope?, savedStateHandle: SavedStateHandle) : StateFlowStore
Link copied to clipboard
class WrapperViewModel(val stateFlowStore: StateFlowStore) : ViewModel

The wrapper ViewModel used by buildOnViewModel.

Properties

Link copied to clipboard

Returns a StateFlowStore where you can put your saved instance state.

Functions

Link copied to clipboard
inline fun <T : ViewModel> Fragment.activityStateFlowViewModel(crossinline provider: (handle: SavedStateHandleStore) -> T): Lazy<T>

Creates a ViewModel with a SavedStateHandleStore, scoped to the Activity.

Link copied to clipboard
inline fun <T : ViewModel> Fragment.activityStateViewModel(crossinline provider: (handle: SavedStateHandle) -> T): Lazy<T>

Creates a ViewModel with a SavedStateHandle, scoped to the Activity.

Link copied to clipboard
inline fun <T : ViewModel> Fragment.activityViewModel(crossinline provider: () -> T): Lazy<T>

Creates a ViewModel scoped to the Activity.

Link copied to clipboard
Link copied to clipboard
fun LifecycleOwner.autoRun(launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else LifecycleCoroutineLauncher(this), onChange: <Error class: unknown class><Unit>? = null, observer: <Error class: unknown class><Unit>): AutoRunner<Unit>

Watches observables for changes. Often useful to keep things in sync (e.g. ViewModel -> UI).

fun ViewModel.autoRun(launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else SimpleCoroutineLauncher(viewModelScope), onChange: <Error class: unknown class><Unit>? = null, observer: <Error class: unknown class><Unit>): AutoRunner<Unit>

Watches observables for changes. Often useful to keep things in sync.

Link copied to clipboard
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.

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.

fun <T : Any> Lazy<WrapperViewModel>.buildOnViewModel(klass: KClass<T>, caster: (Any?) -> T?, provider: BuildOnViewModelContext.() -> T): Lazy<T>

Used internally by buildOnViewModel.

Link copied to clipboard
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.

Link copied to clipboard
fun ViewModel.coAutoRun(launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else SimpleCoroutineLauncher(viewModelScope), onChange: <Error class: unknown class><Unit>? = null, observer: <Error class: unknown class><Unit>): CoAutoRunner<Unit>

Watches observables for changes. Often useful to keep things in sync.

fun LifecycleOwner.coAutoRun(launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else LifecycleCoroutineLauncher(this), onChange: <Error class: unknown class><Unit>? = null, flowTransformer: <Error class: unknown class> = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableStateFlow<Int>? = if (this is CoroutineLauncher) launcher.loading else null, observer: <Error class: unknown class><Unit>): CoAutoRunner<Unit>

Watches observables for changes. Often useful to keep things in sync (e.g. ViewModel -> UI).

Link copied to clipboard
fun <T> LifecycleOwner.derived(launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else LifecycleCoroutineLauncher(this), synchronous: Boolean = true, observer: <Error class: unknown class><T>): StateFlow<T>
fun <T> ViewModel.derived(launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else SimpleCoroutineLauncher(viewModelScope), synchronous: Boolean = true, observer: <Error class: unknown class><T>): StateFlow<T>

Creates a StateFlow that computes its value based on other StateFlows via an autoRun block.

fun <T> LifecycleOwner.derived(initial: T, started: SharingStarted = SharingStarted.Eagerly, launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else LifecycleCoroutineLauncher(this), flowTransformer: <Error class: unknown class> = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableStateFlow<Int>? = if (this is CoroutineLauncher) launcher.loading else null, observer: <Error class: unknown class><T>): StateFlow<T>
fun <T> ViewModel.derived(initial: T, started: SharingStarted = SharingStarted.Eagerly, launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else SimpleCoroutineLauncher(viewModelScope), flowTransformer: <Error class: unknown class> = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableStateFlow<Int>? = if (this is CoroutineLauncher) launcher.loading else null, observer: <Error class: unknown class><T>): StateFlow<T>

Creates a StateFlow that computes its value based on other StateFlows via a suspendable coAutoRun block.

Link copied to clipboard

Consumes and handles EventNotifier's events on the given handler, but only when owner is in >=STARTED state.

Link copied to clipboard
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.

Link copied to clipboard
fun LifecycleStateFlow(lifecycle: Lifecycle): StateFlow<Lifecycle.State>

A StateFlow that tracks the current Lifecycle.State.

Link copied to clipboard
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.

Link copied to clipboard
fun LifecycleOwner.onCreate(block: () -> Unit): <Error class: unknown class>

Runs the given block on every Lifecycle.Event.ON_CREATE.

Link copied to clipboard
fun LifecycleOwner.onCreateOnce(block: () -> Unit): <Error class: unknown class>

Runs the given block once on the next Lifecycle.Event.ON_DESTROY.

Link copied to clipboard
fun Fragment.onCreateView(block: () -> Unit): <Error class: unknown class>

Runs the given block on every Fragment.onCreateView (actually onViewStateRestored).

Link copied to clipboard
fun Fragment.onCreateViewOnce(block: () -> Unit): <Error class: unknown class>

Runs the given block once on the next Fragment.onCreateView (actually onViewStateRestored).

Link copied to clipboard
fun LifecycleOwner.onDestroy(block: () -> Unit): <Error class: unknown class>

Runs the given block on every Lifecycle.Event.ON_DESTROY.

Link copied to clipboard
fun LifecycleOwner.onDestroyOnce(block: () -> Unit): <Error class: unknown class>

Runs the given block once on the next Lifecycle.Event.ON_DESTROY.

Link copied to clipboard
fun Fragment.onDestroyView(block: () -> Unit): <Error class: unknown class>

Runs the given block on every Fragment.onDestroyView.

Link copied to clipboard
fun Fragment.onDestroyViewOnce(block: () -> Unit): <Error class: unknown class>

Runs the given block once on the next Fragment.onDestroyView.

Link copied to clipboard
fun LifecycleOwner.onPause(block: () -> Unit): <Error class: unknown class>

Runs the given block on every Lifecycle.Event.ON_PAUSE.

Link copied to clipboard
fun LifecycleOwner.onPauseOnce(block: () -> Unit): <Error class: unknown class>

Runs the given block once on the next Lifecycle.Event.ON_PAUSE.

Link copied to clipboard
fun LifecycleOwner.onResume(block: () -> Unit): <Error class: unknown class>

Runs the given block on every Lifecycle.Event.ON_RESUME.

Link copied to clipboard
fun LifecycleOwner.onResumeOnce(block: () -> Unit): <Error class: unknown class>

Runs the given block once on the next Lifecycle.Event.ON_RESUME.

Link copied to clipboard
fun LifecycleOwner.onStart(block: () -> Unit): <Error class: unknown class>

Runs the given block on every Lifecycle.Event.ON_START.

Link copied to clipboard
fun LifecycleOwner.onStartOnce(block: () -> Unit): <Error class: unknown class>

Runs the given block once on the next Lifecycle.Event.ON_START.

Link copied to clipboard
fun LifecycleOwner.onStop(block: () -> Unit): <Error class: unknown class>

Runs the given block on every Lifecycle.Event.ON_STOP.

Link copied to clipboard
fun LifecycleOwner.onStopOnce(block: () -> Unit): <Error class: unknown class>

Runs the given block once on the next Lifecycle.Event.ON_STOP.

Link copied to clipboard
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.

Link copied to clipboard
Link copied to clipboard
fun <T> ComponentActivity.savedInstanceState(default: T): ReadOnlyProperty<Any?, MutableStateFlow<T>>
fun <T> Fragment.savedInstanceState(default: T): ReadOnlyProperty<Any?, MutableStateFlow<T>>

Returns a StateFlowStore where you can put your saved instance state.

Link copied to clipboard
Link copied to clipboard
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.

Link copied to clipboard
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.