//reactivestate-core/com.ensody.reactivestate
Package-level declarations¶
Types¶
Name | Summary |
---|---|
ApplyFlowTransform | [common] typealias ApplyFlowTransform<T, R> = Flow<T>.(FlowTransform<T, R>) -> Flow<R> A function applying a Flow.transform and possibly additional Flow configurations. |
AttachedDisposables | [common] interface AttachedDisposables : DisposableHandle A Disposable that can have additional Disposable s attached to it, so they are automatically disposed together with this object. |
AutoRunCallback | [common] typealias AutoRunCallback<T> = Resolver.() -> T Observer callback used by autoRun and AutoRunner. |
AutoRunFlowTransformer | [common] typealias AutoRunFlowTransformer = ApplyFlowTransform<Unit, Unit> Collector of the change events used by autoRun, AutoRunner, coAutoRun and CoAutoRunner. |
AutoRunner | [common] 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. |
AutoRunnerObservable | [common] interface AutoRunnerObservable<T> Base interface for observing a hard-coded AutoRunner instance. |
AutoRunOnChangeCallback | [common] typealias AutoRunOnChangeCallback<T> = (AutoRunner<T>) -> Unit onChange callback used by autoRun and AutoRunner. |
BaseAutoRunner | [common] abstract class BaseAutoRunner : AttachedDisposables Just the minimum interface needed for Resolver. No generic types. |
BaseReactiveState | [common] open class BaseReactiveState<E : ErrorEvents>(scope: CoroutineScope) : SimpleCoroutineLauncher, ReactiveState<E> Base class/delegate for ViewModels and other objects that can trigger one-time events/actions and handle errors. |
BaseSuspendMutableValueFlow | [common] @ExperimentalReactiveStateApi abstract class BaseSuspendMutableValueFlow<T> : ValueFlow<T> , SuspendMutableValueFlow<T> Base class for StateFlows that can be mutated only via suspend functions - in contrast to assigning the value. |
CoAutoRunCallback | [common] typealias CoAutoRunCallback<T> = suspend Resolver.() -> T Observer callback used by suspendable coAutoRun and CoAutoRunner. |
CoAutoRunner | [common] class CoAutoRunner<T>(val launcher: CoroutineLauncher, onChange: CoAutoRunOnChangeCallback<T>? = null, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableValueFlow<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. |
CoAutoRunOnChangeCallback | [common] typealias CoAutoRunOnChangeCallback<T> = suspend (CoAutoRunner<T>) -> Unit onChange callback used by suspendable coAutoRun and CoAutoRunner. |
CoroutineDispatcherConfig | [common] interface CoroutineDispatcherConfig Interface for a common set of CoroutineDispatchers. |
CoroutineLauncher | [common] interface CoroutineLauncher Interface for launching coroutines with error handling and loading state tracking. |
DefaultCoroutineDispatcherConfig | [common] object DefaultCoroutineDispatcherConfig : CoroutineDispatcherConfig The default CoroutineDispatcherConfig, mapping to Dispatchers. |
DefaultOneTimeEvent | [common] class DefaultOneTimeEvent<T> : OneTimeEvent<T> |
DependencyAccessor | [common] @Target(allowedTargets = [AnnotationTarget.PROPERTY]) annotation class DependencyAccessor Marks dependency injection system accessors, so direct access must be explicitly opted in. |
Disposable | [common] typealias Disposable = DisposableHandle An object that can be disposed/deactivated/canceled by calling dispose() . |
DisposableGroup | [common] interface DisposableGroup : DisposableHandle A Disposable that can dispose multiple Disposable and Job instances at once. |
DisposableValue | [common] class DisposableValue<T>(val value: T, disposer: () -> Unit) : DisposableHandle A value that must be explicitly disposed when it’s not needed anymore. |
ErrorEvents | [common] interface ErrorEvents Events interface with a simple onError event (e.g. for use with EventNotifier). |
EventNotifier | [common] interface EventNotifier<T> : MutableFlow<T.() -> Unit> This is used to send events to an observer. All events are queued for later processing. |
ExperimentalReactiveStateApi | [common] annotation class ExperimentalReactiveStateApi This feature is not stable yet and can introduce breaking API changes in minor releases. |
FlowTransform | [common] typealias FlowTransform<T, R> = suspend FlowCollector<R>.(T) -> Unit A function which can be passed to Flow.transform. |
FrozenAutoRunnerObservable | [common] class FrozenAutoRunnerObservable<T, O : AutoRunnerObservable<T>>(val observable: AutoRunnerObservable<T>) |
InMemoryStateFlowStore | [common] 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. |
InternalBaseAutoRunner | [common] abstract class InternalBaseAutoRunner(val launcher: CoroutineLauncher, flowTransformer: AutoRunFlowTransformer, immediate: Boolean) : BaseAutoRunner |
JobDisposable | [common] class JobDisposable(job: Job) : DisposableHandle A Disposable wrapping a Job. |
JvmSerializable | [common] expect interface JvmSerializable Alias for java.io.Serializable on JVM. Empty interface otherwise.[nonJvm, jvmCommon] [nonJvm] actual interface JvmSerializable [jvmCommon] actual typealias JvmSerializable = <Error class: unknown class> |
MutableFlow | [common] interface MutableFlow<T> : Flow<T> , FlowCollector<T> A Flow where you can emit/tryEmit values into (backed by a Channel). |
MutableValueFlow | [common] interface MutableValueFlow<T> : ValueFlow<T> , MutableStateFlow<T> A version of MutableStateFlow that provides better support for mutable values via the update operation. Assigning to .value still has distinctUntilChanged behavior, but emit /tryEmit and update always trigger a change event. |
NamespacedStateFlowStore | [common] class NamespacedStateFlowStore(store: StateFlowStore, namespace: String) : StateFlowStore A wrapper StateFlowStore that prefixes every key with a namespace. |
OnDispose | [common] class OnDispose(function: () -> Unit) : DisposableHandle A Disposable executing the given function on dispose() . |
OneTimeEvent | [common] interface OneTimeEvent<T> Simple synchronous one-time event. Once trigger is called, subsequent observe calls are triggered immediately. |
OnReactiveStateAttached | [common] interface OnReactiveStateAttached Implement this interface to get notified of every ReactiveState added to your object. |
RawSerializer | [common] interface RawSerializer<T> : JvmSerializable Handles custom serialization/deserialization. Useful e.g. with JvmSerializerReplacement. |
ReactiveState | [common] interface ReactiveState<E : ErrorEvents> : CoroutineLauncher An interface for ViewModels and any other objects that can trigger one-time events/actions and handle errors. |
ReactiveStateContext | [common] @ExperimentalReactiveStateApi interface ReactiveStateContext Contains all values which are part of the |
ReactiveViewModel | [common] @ExperimentalReactiveStateApi abstract class ReactiveViewModel(val context: ReactiveViewModelContext) : BaseReactiveState<ErrorEvents> Base class for ViewModels which provide a context for common APIs across ViewModels. |
ReactiveViewModelContext | [common] @ExperimentalReactiveStateApi interface ReactiveViewModelContext : ReactiveStateContext |
RefreshableStateFlow | [common] @ExperimentalReactiveStateApi interface RefreshableStateFlow<T> : StateFlow<T> A StateFlow which can retrieve a new value e.g. from a backend via refresh. |
Resolver | [common] class Resolver(val autoRunner: BaseAutoRunner, val once: Boolean = false) Tracks observables for AutoRunner and CoAutoRunner. |
RevisionedValue | [common] interface RevisionedValue<T> |
Serializable | [common] typealias Serializable = JvmSerializable |
SimpleCoroutineLauncher | [common] open class SimpleCoroutineLauncher(val launcherScope: CoroutineScope) : CoroutineLauncher Simple default implementation of a CoroutineLauncher which uses a given CoroutineScope. |
StateFlowStore | [common] interface StateFlowStore Base interface for a temporary observable key-value store. |
StateFlowStoreFactory | [common] typealias StateFlowStoreFactory = (CoroutineScope) -> StateFlowStore A factory function creating a StateFlowStore. |
SuspendMutableValueFlow | [common] @ExperimentalReactiveStateApi interface SuspendMutableValueFlow<T> : ValueFlow<T> A StateFlow that can be mutated only via suspend functions - in contrast to assigning the value. |
ValueFlow | [common] interface ValueFlow<T> : StateFlow<T> A version of StateFlow that can explicitly trigger value changes without equality checks. |
WhileUsed | [common] 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). |
WhileUsedReferenceToken | [common] class WhileUsedReferenceToken : DisposableGroup The reference token passed to the WhileUsed builder function. |
Wrapped | [common] data class Wrapped<T>(val value: T) : JvmSerializable, ReadOnlyProperty<Any?, T> Wraps a value. Together with nullability can model an Option /Maybe . |
Properties¶
Name | Summary |
---|---|
dispatchers | [common] var dispatchers: CoroutineDispatcherConfig The currently active CoroutineDispatcherConfig. |
Functions¶
Name | Summary |
---|---|
addDelay | [common] 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. |
afterUpdate | [common] fun <T> MutableStateFlow<T>.afterUpdate(setter: (T) -> Unit): MutableStateFlow<T> Returns a new MutableStateFlow that calls setter after doing the actual value update. |
attachTo | [common] fun ReactiveState<out ErrorEvents>.attachTo(owner: Any) |
autoRun | [common] fun CoroutineLauncher.autoRun(onChange: AutoRunOnChangeCallback<Unit>? = null, observer: AutoRunCallback<Unit>): AutoRunner<Unit> Watches observables for changes. Often useful to keep things in sync (e.g. CoroutineLauncher -> UI). [common] 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). |
beforeUpdate | [common] fun <T> MutableStateFlow<T>.beforeUpdate(setter: (T) -> Unit): MutableStateFlow<T> Returns a new MutableStateFlow that calls setter before doing the actual value update. |
childReactiveState | [common] fun <E : ErrorEvents, P : ReactiveState<out E>, RS : ReactiveState<E>> P.childReactiveState(block: () -> RS): ReadOnlyProperty<Any?, RS> Creates and attaches a child ReactiveState. |
coAutoRun | [common] fun CoroutineLauncher.coAutoRun(onChange: CoAutoRunOnChangeCallback<Unit>? = null, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableValueFlow<Int>? = loading, observer: CoAutoRunCallback<Unit>): CoAutoRunner<Unit> Watches observables for changes. Often useful to keep things in sync (e.g. CoroutineLauncher -> UI). [common] fun CoroutineScope.coAutoRun(launcher: CoroutineLauncher = SimpleCoroutineLauncher(this), onChange: CoAutoRunOnChangeCallback<Unit>? = null, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableValueFlow<Int>? = launcher.loading, observer: CoAutoRunCallback<Unit>): CoAutoRunner<Unit> Watches observables for changes. Often useful to keep things in sync (e.g. ViewModel -> UI). |
conflatedMap | [common] 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. |
conflatedTransform | [common] 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. |
conflatedWorker | [common] fun <T, R> Flow<T>.conflatedWorker(timeoutMillis: Long = 0, transform: FlowTransform<T, R>): Flow<R> Executes each lambda in a Flow using conflatedMap. |
coRunWithResolver | [common] 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. |
debounceWorker | [common] 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. |
decrement | [common] fun MutableValueFlow<Int>.decrement(amount: Int = 1): Int Atomically decrement this MutableValueFlow by amount. |
derived | [common] 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. |
derived | [common] 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. [common] fun <T> CoroutineLauncher.derived(initial: T, started: SharingStarted = SharingStarted.Eagerly, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableValueFlow<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: MutableValueFlow<Int>? = null, observer: CoAutoRunCallback<T>): StateFlow<T> Creates a StateFlow that computes its value based on other StateFlows via a suspendable coAutoRun block. |
derivedWhileSubscribed | [common] fun <T> derivedWhileSubscribed(initial: T, flowTransformer: AutoRunFlowTransformer = { conflatedWorker(transform = it) }, dispatcher: CoroutineDispatcher = dispatchers.main, withLoading: MutableValueFlow<Int>? = null, observer: CoAutoRunCallback<T>): StateFlow<T> Creates a StateFlow that computes its value based on other StateFlows via a suspendable coAutoRun block. |
DisposableGroup | [common] fun DisposableGroup(): DisposableGroup Constructs a DisposableGroup. |
disposeOnCompletionOf | [common] fun Disposable.disposeOnCompletionOf(launcher: CoroutineLauncher): Disposable Disposes the Disposable when CoroutineLauncher completes (including cancellation). [common] fun Disposable.disposeOnCompletionOf(context: CoroutineContext): Disposable Disposes the Disposable when CoroutineContext completes (including cancellation). [common] fun Disposable.disposeOnCompletionOf(scope: CoroutineScope): Disposable Disposes the Disposable when CoroutineScope completes (including cancellation). [common] fun Disposable.disposeOnCompletionOf(job: Job): Disposable Disposes the Disposable when Job completes (including cancellation). |
EventNotifier | [common] fun <T> EventNotifier(capacity: Int = Channel.UNLIMITED): EventNotifier<T> Creates an EventNotifier. |
get | [common] fun <T> Resolver.get(data: WhileUsed<T>): T Returns WhileUsed’s value and keeps it alive as long as it’s still used. [common] fun <T> Resolver.get(data: StateFlow<T>): T Returns StateFlow.value and tracks the observable (on the MainScope ). |
getData | [common] fun <T> StateFlowStore.getData(default: T): ReadOnlyProperty<Any?, MutableValueFlow<T>> For use with by delegation. Returns the StateFlowStore entry for the key that equals the property name. |
handleEvents | [common] suspend fun <T : ErrorEvents> EventNotifier<T>.handleEvents(handler: T) Consumes and handles EventNotifier’s events on the given handler. |
increment | [common] fun MutableValueFlow<Int>.increment(amount: Int = 1): Int Atomically increment this MutableValueFlow by amount. |
incrementFrom | [common] @JvmName(name = "incrementFromBoolean") suspend fun MutableValueFlow<Int>.incrementFrom(flow: StateFlow<Boolean>) suspend fun MutableValueFlow<Int>.incrementFrom(flow: StateFlow<Int>) Keeps this incrementedincrement by the latest value in the given flow. |
invokeOnCompletion | [common] fun CoroutineLauncher.invokeOnCompletion(handler: CompletionHandler): Disposable Helper for adding a completion handler to a CoroutineLauncher. [common] fun CoroutineContext.invokeOnCompletion(handler: CompletionHandler): Disposable Helper for adding a completion handler to a CoroutineContext. [common] fun CoroutineScope.invokeOnCompletion(handler: CompletionHandler): Disposable Helper for adding a completion handler to a CoroutineScope. |
isFatal | [common, jvmCommon, nonJvm] [common] expect fun Throwable.isFatal(): Boolean [jvmCommon, nonJvm] actual fun Throwable.isFatal(): Boolean |
JvmSerializerReplacement | [common] expect fun <T : Any> JvmSerializerReplacement(serializer: RawSerializer<T>, value: T): Any Simplifies implementing custom java.io.Serializable (JvmSerializable) logic.[jvmCommon, nonJvm] [jvmCommon] actual fun <T : Any> JvmSerializerReplacement(serializer: RawSerializer<T>, value: T): Any [nonJvm] actual fun <T : Any> JvmSerializerReplacement(serializer: RawSerializer<T>, value: T): Any |
latestWorker | [common] 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. |
lazyProperty | [common] fun <T> lazyProperty(block: (property: KProperty<*>) -> T): ReadOnlyProperty<Any?, T> A helper for creating a lazily computed ReadOnlyProperty based on a KProperty. |
MutableFlow | [common] fun <T> MutableFlow(capacity: Int = Channel.RENDEZVOUS, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND): MutableFlow<T> Creates a MutableFlow. |
MutableValueFlow | [common] fun <T> MutableValueFlow(value: T, setter: (value: T) -> Unit? = null): MutableValueFlow<T> Instantiates a MutableValueFlow with the given initial value and optional setter to intercept mutations. |
onStateSubscription | [common] fun <T> MutableStateFlow<T>.onStateSubscription(block: suspend FlowCollector<T>.() -> Unit): MutableStateFlow<T> Similar to MutableStateFlow.onSubscription but returns a MutableStateFlow. [common] fun <T> StateFlow<T>.onStateSubscription(block: suspend FlowCollector<T>.() -> Unit): StateFlow<T> Similar to StateFlow.onSubscription but returns a StateFlow. |
propertyName | [common] inline fun <T> propertyName(crossinline block: (name: String) -> T): ReadOnlyProperty<Any?, T> A lazyProperty that only receives the KProperty.name as its argument. |
ReactiveStateContext | [common] @ExperimentalReactiveStateApi fun ReactiveStateContext(scope: CoroutineScope, stateFlowStore: StateFlowStore): ReactiveStateContext |
ReactiveViewModelContext | [common] @ExperimentalReactiveStateApi fun ReactiveViewModelContext(reactiveStateContext: ReactiveStateContext): ReactiveViewModelContext |
replace | [common] fun <T> MutableStateFlow<T>.replace(block: T.() -> T): T Replaces the MutableStateFlow.value with block’s return value. |
runCatchingNonFatal | [common] inline fun <T> runCatchingNonFatal(block: () -> T): Result<T> Similar to the stdlib runCatching, but uses throwIfFatal to re-throw fatal exceptions immediately. |
runCatchingNonFatal | [common] 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. |
runWithResolver | [common] 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. |
sharedFlow | [common] 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). |
shareOnDemand | [common] 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). |
stateOnDemand | [common] 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). |
SuspendMutableValueFlow | [common] @ExperimentalReactiveStateApi fun <T> SuspendMutableValueFlow(value: T, setter: suspend (value: T) -> Unit): SuspendMutableValueFlow<T> |
throwIfFatal | [common] inline fun <T : Throwable> T.throwIfFatal(): T Throws this exception if it’s fatal. Otherwise returns it. |
toMutable | [common] 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. |
validUntil | [common] fun <T> validUntil(invalidateOn: (invalidate: () -> Unit) -> Any?): ReadWriteProperty<Any?, T> Creates an automatically invalidated property. |
withErrorReporting | [common] 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. [common] inline fun withErrorReporting(onError: (error: Throwable) -> Unit, block: () -> Unit) Executes the given block, catching any errors and calling onError, but handling CancellationException. |
withRefresh | [common] @ExperimentalReactiveStateApi fun <T> MutableStateFlow<T>.withRefresh(block: suspend MutableStateFlow<T>.(force: Boolean) -> Unit): RefreshableStateFlow<T> @ExperimentalReactiveStateApi fun <T> StateFlow<T>.withRefresh(block: suspend StateFlow<T>.(force: Boolean) -> Unit): RefreshableStateFlow<T> |
withSetter | [common] 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. |