Package-level declarations

Types

Link copied to clipboard
typealias ApplyFlowTransform<T, R> = Flow<T>.(FlowTransform<T, R>) -> Flow<R>

A function applying a Flow.transform and possibly additional Flow configurations.

Link copied to clipboard
interface AttachedDisposables : DisposableHandle

A Disposable that can have additional Disposables attached to it, so they are automatically disposed together with this object.

Link copied to clipboard
typealias AutoRunCallback<T> = Resolver.() -> T

Observer callback used by autoRun and AutoRunner.

Link copied to clipboard

Collector of the change events used by autoRun, AutoRunner, coAutoRun and CoAutoRunner.

Link copied to clipboard
class AutoRunner<T>(val launcher: CoroutineLauncher, onChange: AutoRunOnChangeCallback<T>? = null, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, immediate: Boolean = false, observer: AutoRunCallback<T>) : InternalBaseAutoRunner

Watches observables for changes. Often useful to keep things in sync (e.g. ViewModel -> UI). This is the synchronous version. See CoAutoRunner for the suspension function based version.

Link copied to clipboard

Base interface for observing a hard-coded AutoRunner instance.

Link copied to clipboard

onChange callback used by autoRun and AutoRunner.

Link copied to clipboard

Just the minimum interface needed for Resolver. No generic types.

Link copied to clipboard
open class BaseReactiveState<E : ErrorEvents>(val scope: CoroutineScope) : ReactiveState<E>

Base class/delegate for ViewModels and other objects that can trigger one-time events/actions and handle errors.

Link copied to clipboard
typealias CoAutoRunCallback<T> = suspend Resolver.() -> T

Observer callback used by suspendable coAutoRun and CoAutoRunner.

Link copied to clipboard
class CoAutoRunner<T>(val launcher: CoroutineLauncher, onChange: CoAutoRunOnChangeCallback<T>? = null, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableStateFlow<Int>? = launcher.loading, immediate: Boolean = false, observer: CoAutoRunCallback<T>) : InternalBaseAutoRunner

Watches observables for changes. Often useful to keep things in sync (e.g. ViewModel -> UI). This is the suspension function based version. See AutoRunner for the synchronous version.

Link copied to clipboard
typealias CoAutoRunOnChangeCallback<T> = suspend (CoAutoRunner<T>) -> Unit

onChange callback used by suspendable coAutoRun and CoAutoRunner.

Link copied to clipboard
class ContextualVal<T>(val name: String, var default: (CoroutineContext) -> T)

A val for which the value can be set via the coroutineContext.

Link copied to clipboard
class ContextualValSuspend<T>(val name: String, var default: suspend (CoroutineContext) -> T)

A val for which the value can be set via the coroutineContext.

Link copied to clipboard

Interface for a common set of CoroutineDispatchers.

Link copied to clipboard

Interface for launching coroutines with error handling and loading state tracking.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.PROPERTY])
annotation class DependencyAccessor

Marks dependency injection system accessors, so direct access must be explicitly opted in.

Link copied to clipboard
typealias Disposable = DisposableHandle

An object that can be disposed/deactivated/canceled by calling dispose().

Link copied to clipboard
interface DisposableGroup : DisposableHandle

A Disposable that can dispose multiple Disposable and Job instances at once.

Link copied to clipboard
class DisposableValue<T>(val value: T, disposer: () -> Unit) : DisposableHandle

A value that must be explicitly disposed when it's not needed anymore.

Link copied to clipboard
interface ErrorEvents

Events interface with a simple onError event (e.g. for use with EventNotifier).

Link copied to clipboard
interface EventNotifier<T> : MutableFlow<T.() -> Unit>

This is used to send events to an observer. All events are queued for later processing.

Link copied to clipboard

This feature is not stable yet and can introduce breaking API changes in minor releases.

Link copied to clipboard
typealias FlowTransform<T, R> = suspend FlowCollector<R>.(T) -> Unit

A function which can be passed to Flow.transform.

Link copied to clipboard
class InMemoryStateFlowStore(val underlyingData: MutableMap<String, Any?> = mutableMapOf()) : StateFlowStore

A StateFlowStore that can be used for unit tests or non-Android parts of multiplatform projects.

Link copied to clipboard
abstract class InternalBaseAutoRunner(val launcher: CoroutineLauncher, flowTransformer: AutoRunFlowTransformer, immediate: Boolean) : BaseAutoRunner
Link copied to clipboard
class JobDisposable(job: Job) : DisposableHandle

A Disposable wrapping a Job.

Link copied to clipboard
expect interface JvmSerializable

Alias for java.io.Serializable on JVM. Empty interface otherwise.

actual typealias JvmSerializable = <Error class: unknown class>
actual interface JvmSerializable
Link copied to clipboard
class LazySuspend<T>(block: suspend () -> T)

A suspend/coroutine version of Lazy.

Link copied to clipboard
interface MutableFlow<T> : Flow<T> , FlowCollector<T>

A Flow where you can emit/tryEmit values into (backed by a Channel).

Link copied to clipboard

A wrapper StateFlowStore that prefixes every key with a namespace.

Link copied to clipboard
class OnDispose(function: () -> Unit) : DisposableHandle

A Disposable executing the given function on dispose().

Link copied to clipboard

A mechanism for ViewModel initialization-time tasks like repository cache refresh. Use via ContextualOnInit.

Link copied to clipboard

When the ViewModel is ready this API allows launching coroutines.

Link copied to clipboard

Implement this interface to get notified of every ReactiveState added to your object.

Link copied to clipboard

Implement this interface on your ReactiveState to get notified it's attached to a parent (screen or ReactiveState).

Link copied to clipboard

Handles custom serialization/deserialization. Useful e.g. with JvmSerializerReplacement.

Link copied to clipboard

An interface for ViewModels and any other objects that can trigger one-time events/actions and handle errors.

Link copied to clipboard
data class ReactiveStateContext(val scope: CoroutineScope)

Contains all values which are part of the ViewModel build process.

Link copied to clipboard
abstract class ReactiveViewModel(val scope: CoroutineScope) : CoroutineLauncher

Base class for ViewModels.

Link copied to clipboard

A StateFlow which can retrieve a new value e.g. from a backend via refresh.

Link copied to clipboard
class Resolver(val autoRunner: BaseAutoRunner, val once: Boolean = false)

Tracks observables for AutoRunner and CoAutoRunner.

Link copied to clipboard
interface RevisionedValue<T>
Link copied to clipboard
open class SimpleCoroutineLauncher(val scope: CoroutineScope) : CoroutineLauncher

Simple default implementation of a CoroutineLauncher which uses a given CoroutineScope.

Link copied to clipboard
interface StateFlowStore

Base interface for a temporary observable key-value store.

Link copied to clipboard
typealias StateFlowStoreFactory = (CoroutineScope) -> StateFlowStore

A factory function creating a StateFlowStore.

Link copied to clipboard
class WhileUsed<T>(retentionMillis: Long = 0, destructor: (T) -> Unit? = null, builder: (WhileUsedReferenceToken) -> T)

A reference-counted value that is created on-demand and freed once nobody uses it (whereas by lazy is never freed).

Link copied to clipboard

The reference token passed to the WhileUsed builder function.

Link copied to clipboard
data class Wrapped<T>(val value: T) : JvmSerializable, ReadOnlyProperty<Any?, T>

Wraps a value. Together with nullability can model an Option/Maybe.

Properties

Functions

Link copied to clipboard
fun <T> Flow<T>.addDelay(timeoutMillis: Long): Flow<T>

Adds a timeoutMillis delay to a Flow. If delay is zero or negative this is a no-op.

Link copied to clipboard
fun <T> MutableStateFlow<T>.afterUpdate(setter: (T) -> Unit): MutableStateFlow<T>

Returns a new MutableStateFlow that calls setter after doing the actual value update.

Link copied to clipboard

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

fun CoroutineScope.autoRun(launcher: CoroutineLauncher = SimpleCoroutineLauncher(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).

Link copied to clipboard
fun <T> MutableStateFlow<T>.beforeUpdate(setter: (T) -> Unit): MutableStateFlow<T>

Returns a new MutableStateFlow that calls setter before doing the actual value update.

Link copied to clipboard

Creates and attaches a child ReactiveState.

Link copied to clipboard
fun CoroutineLauncher.coAutoRun(onChange: CoAutoRunOnChangeCallback<Unit>? = null, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableStateFlow<Int>? = loading, observer: CoAutoRunCallback<Unit>): CoAutoRunner<Unit>

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

fun CoroutineScope.coAutoRun(launcher: CoroutineLauncher = SimpleCoroutineLauncher(this), onChange: CoAutoRunOnChangeCallback<Unit>? = null, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableStateFlow<Int>? = launcher.loading, observer: CoAutoRunCallback<Unit>): CoAutoRunner<Unit>

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

Link copied to clipboard
inline fun <T, R> Flow<T>.conflatedMap(timeoutMillis: Long = 0, crossinline transform: suspend (value: T) -> R): Flow<R>

Maps a conflated Flow with timeoutMillis delay between the first and last element.

Link copied to clipboard
inline fun <T, R> Flow<T>.conflatedTransform(timeoutMillis: Long = 0, crossinline transform: suspend FlowCollector<R>.(value: T) -> Unit): Flow<R>

Transforms a conflated Flow with timeoutMillis delay between the first and last element.

Link copied to clipboard
fun <T, R> Flow<T>.conflatedWorker(timeoutMillis: Long = 0, transform: FlowTransform<T, R>): Flow<R>

Executes each lambda in a Flow using conflatedMap.

Link copied to clipboard

This has to be added to the CoroutineScope via CoroutineScope.plus in order for ContextualVal to work.

Link copied to clipboard
suspend fun <T> coRunWithResolver(block: suspend Resolver.() -> T): T

Runs block with a Resolver as the this argument, so you can evaluate an observer block without subscribing.

Link copied to clipboard
fun <T, R> Flow<T>.debounceWorker(timeoutMillis: Long = 0, transform: FlowTransform<T, R>): Flow<R>

Executes each lambda in a Flow using debounce and map.

Link copied to clipboard
fun MutableStateFlow<Int>.decrement(amount: Int = 1): Int

Atomically decrements this MutableStateFlow by amount (default 1) and returns previous value.

Link copied to clipboard
fun <T> derived(synchronous: Boolean = true, cache: Boolean = true, observer: AutoRunCallback<T>): StateFlow<T>

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

Link copied to clipboard
fun <T> CoroutineLauncher.derived(synchronous: Boolean = true, cache: Boolean = synchronous, observer: AutoRunCallback<T>): StateFlow<T>
fun <T> CoroutineScope.derived(launcher: CoroutineLauncher = SimpleCoroutineLauncher(this), synchronous: Boolean = true, cache: Boolean = synchronous, observer: AutoRunCallback<T>): StateFlow<T>

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

fun <T> CoroutineLauncher.derived(initial: T, started: SharingStarted = SharingStarted.Eagerly, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableStateFlow<Int>? = loading, observer: CoAutoRunCallback<T>): StateFlow<T>
fun <T> CoroutineScope.derived(initial: T, started: SharingStarted = SharingStarted.Eagerly, launcher: CoroutineLauncher = SimpleCoroutineLauncher(this), flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableStateFlow<Int>? = null, observer: CoAutoRunCallback<T>): StateFlow<T>

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

Link copied to clipboard
fun <T> derivedWhileSubscribed(initial: T, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableStateFlow<Int>? = null, observer: CoAutoRunCallback<T>): StateFlow<T>

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

Link copied to clipboard
Link copied to clipboard

Disposes the Disposable when CoroutineLauncher completes (including cancellation).

Disposes the Disposable when CoroutineContext completes (including cancellation).

fun Disposable.disposeOnCompletionOf(scope: CoroutineScope): Disposable

Disposes the Disposable when CoroutineScope completes (including cancellation).

Disposes the Disposable when Job completes (including cancellation).

Link copied to clipboard
fun <T> EventNotifier(capacity: Int = Channel.UNLIMITED): EventNotifier<T>

Creates an EventNotifier.

Link copied to clipboard
fun <T> Resolver.get(data: WhileUsed<T>): T

Returns WhileUsed's value and keeps it alive as long as it's still used.

fun <T> Resolver.get(data: StateFlow<T>): T

Returns StateFlow.value and tracks the observable (on the MainScope).

Link copied to clipboard
fun <T> MutableStateFlow<T>.getAndReplace(block: T.() -> T): T

A version of getAndUpdate where the current value is passed via this.

Link copied to clipboard
fun <T> StateFlowStore.getData(default: T): ReadOnlyProperty<Any?, MutableStateFlow<T>>

For use with by delegation. Returns the StateFlowStore entry for the key that equals the property name.

Link copied to clipboard
suspend fun <T : ErrorEvents> EventNotifier<T>.handleEvents(handler: T)

Consumes and handles EventNotifier's events on the given handler.

Link copied to clipboard
fun MutableStateFlow<Int>.increment(amount: Int = 1): Int

Atomically increments this MutableStateFlow by amount (default 1) and returns previous value.

Link copied to clipboard
@JvmName(name = "incrementFromBoolean")
suspend fun MutableStateFlow<Int>.incrementFrom(flow: StateFlow<Boolean>)
suspend fun MutableStateFlow<Int>.incrementFrom(flow: StateFlow<Int>)

Keeps this incrementedincrement by the latest value in the given flow.

Link copied to clipboard
fun CoroutineLauncher.invokeOnCompletion(handler: CompletionHandler): Disposable

Helper for adding a completion handler to a CoroutineLauncher.

fun CoroutineContext.invokeOnCompletion(handler: CompletionHandler): Disposable

Helper for adding a completion handler to a CoroutineContext.

fun CoroutineScope.invokeOnCompletion(handler: CompletionHandler): Disposable

Helper for adding a completion handler to a CoroutineScope.

Link copied to clipboard
expect fun Throwable.isFatal(): Boolean
actual fun Throwable.isFatal(): Boolean
actual fun Throwable.isFatal(): Boolean
Link copied to clipboard
expect fun <T : Any> JvmSerializerReplacement(serializer: RawSerializer<T>, value: T): Any

Simplifies implementing custom java.io.Serializable (JvmSerializable) logic.

actual fun <T : Any> JvmSerializerReplacement(serializer: RawSerializer<T>, value: T): Any
actual fun <T : Any> JvmSerializerReplacement(serializer: RawSerializer<T>, value: T): Any
Link copied to clipboard
fun <T, R> Flow<T>.latestWorker(timeoutMillis: Long = 0, transform: FlowTransform<T, R>): Flow<R>

Executes each lambda in a Flow using debounce and mapLatest.

Link copied to clipboard
fun <T> lazyProperty(block: (property: KProperty<*>) -> T): ReadOnlyProperty<Any?, T>

A helper for creating a lazily computed ReadOnlyProperty based on a KProperty.

Link copied to clipboard
fun <T> MutableFlow(capacity: Int = Channel.RENDEZVOUS, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND): MutableFlow<T>

Creates a MutableFlow.

Link copied to clipboard
Link copied to clipboard
fun <T> MutableStateFlow<T>.onStateSubscription(block: suspend FlowCollector<T>.() -> Unit): MutableStateFlow<T>

Similar to MutableStateFlow.onSubscription but returns a MutableStateFlow.

fun <T> StateFlow<T>.onStateSubscription(block: suspend FlowCollector<T>.() -> Unit): StateFlow<T>

Similar to StateFlow.onSubscription but returns a StateFlow.

Link copied to clipboard
inline fun <T> propertyName(crossinline block: (name: String) -> T): ReadOnlyProperty<Any?, T>

A lazyProperty that only receives the KProperty.name as its argument.

Link copied to clipboard
fun <T> MutableStateFlow<T>.replace(block: T.() -> T)

A version of update where the current value is passed via this.

Link copied to clipboard
fun <T> MutableStateFlow<T>.replaceAndGet(block: T.() -> T): T

This is a version of updateAndGet.

Link copied to clipboard
fun requireContextualValRoot(scope: CoroutineScope)

Throws an exception if ContextualValRoot was not added to the CoroutineContext/CoroutineScope.

Link copied to clipboard
inline fun <T> runCatchingNonFatal(block: () -> T): Result<T>

Similar to the stdlib runCatching, but uses throwIfFatal to re-throw fatal exceptions immediately.

Link copied to clipboard
inline fun <T, R> T.runCatchingNonFatal(block: T.() -> R): Result<R>

Similar to the stdlib runCatching, but uses throwIfFatal to re-throw fatal exceptions immediately.

Link copied to clipboard
fun <T> runWithResolver(block: Resolver.() -> T): T

Runs block with a Resolver as the this argument, so you can evaluate an observer block without subscribing.

Link copied to clipboard
inline fun <T> sharedFlow(replay: Int = 0, context: CoroutineContext = EmptyCoroutineContext, crossinline observer: suspend ProducerScope<T>.() -> Unit): SharedFlow<T>

Creates a computed SharedFlow without requiring a CoroutineScope (unlike shareIn).

Link copied to clipboard
fun <T> Flow<T>.shareOnDemand(replay: Int = 0, context: CoroutineContext = EmptyCoroutineContext): SharedFlow<T>

Turns this Flow into a SharedFlow without requiring a CoroutineScope (unlike shareIn).

Link copied to clipboard
fun <T> Flow<T>.stateOnDemand(initial: T, context: CoroutineContext = EmptyCoroutineContext, synchronous: Boolean = true, emitValueOnStart: Boolean = true): StateFlow<T>
fun <T> Flow<T>.stateOnDemand(context: CoroutineContext = EmptyCoroutineContext, synchronous: Boolean = true, emitValueOnStart: Boolean = true, getter: (previous: Wrapped<T>?) -> T): StateFlow<T>

Turns this Flow into a StateFlow without requiring a CoroutineScope (unlike stateIn).

Link copied to clipboard
inline fun <T : Throwable> T.throwIfFatal(): T

Throws this exception if it's fatal. Otherwise returns it.

Link copied to clipboard
fun <T> StateFlow<T>.toMutable(setter: StateFlow<T>.(T) -> Unit): MutableStateFlow<T>

Converts this StateFlow to a MutableStateFlow that calls setter for doing the actual value update.

Link copied to clipboard
Link copied to clipboard
fun <T> validUntil(invalidateOn: (invalidate: () -> Unit) -> Any?): ReadWriteProperty<Any?, T>

Creates an automatically invalidated property.

Link copied to clipboard
inline fun <E : ErrorEvents> withErrorReporting(eventNotifier: EventNotifier<E>, block: () -> Unit)
suspend fun <E : ErrorEvents> withErrorReporting(eventNotifier: EventNotifier<E>, onError: suspend (error: Throwable) -> Unit?, block: suspend () -> Unit)

Executes the given block, catching any errors and reporting them to the given eventNotifier.

inline fun withErrorReporting(onError: (error: Throwable) -> Unit, block: () -> Unit)

Executes the given block, catching any errors and calling onError, but handling CancellationException.

Link copied to clipboard
fun <T> MutableStateFlow<T>.withRefresh(block: suspend MutableStateFlow<T>.(force: Boolean) -> Unit): RefreshableStateFlow<T>
fun <T> StateFlow<T>.withRefresh(block: suspend StateFlow<T>.(force: Boolean) -> Unit): RefreshableStateFlow<T>
Link copied to clipboard
fun <T> MutableStateFlow<T>.withSetter(setter: MutableStateFlow<T>.(T) -> Unit): MutableStateFlow<T>

Returns a new MutableStateFlow that calls setter instead of doing the actual value update.