MutableRemember

class MutableRemember<T>(stopListeningWhenOverridden: Boolean = true, useLastWhileLoading: Boolean = false, coroutineContext: CoroutineContext = Dispatchers.Unconfined, initialValue: ReactiveContext.() -> T) : BaseReactive<T> , ReactiveWithMutableValue<T> (source)

A mutable reactive value that can be set directly or calculated automatically from dependencies.

When not overridden, the value is calculated in a reactive context and updates automatically when dependencies change. When overridden by direct assignment, automatic calculation is paused until reset() is called.

Note:

  • MutableRemember is lazy: if it has no listeners, it will not calculate a value.

  • Listeners are only notified if the calculated or set value changes.

  • The reset() method restores automatic calculation and updates the value from dependencies.

Parameters

coroutineContext

The coroutine context for running the calculation.

initialValue

The block to compute the initial value reactively.

Constructors

Link copied to clipboard
constructor(stopListeningWhenOverridden: Boolean = true, useLastWhileLoading: Boolean = false, coroutineContext: CoroutineContext = Dispatchers.Unconfined, initialValue: ReactiveContext.() -> T)

Properties

Link copied to clipboard
Link copied to clipboard
open override var state: ReactiveState<T>
Link copied to clipboard
@set:JvmName(name = "setValue2")
var <T> MutableValue<T>.value: T

Functions

Link copied to clipboard
fun Listenable.addAndRunListener(listener: () -> Unit): () -> Unit

Adds a listener and immediately runs it once.

Link copied to clipboard
abstract fun addListener(listener: () -> Unit): () -> Unit

Adds the listener to be called every time this event fires.

Link copied to clipboard
@JvmName(name = "writableStringAsByte")
fun MutableReactive<String>.asByte(): MutableReactive<Byte?>
Link copied to clipboard
@JvmName(name = "writableStringAsByteHex")
fun MutableReactive<String>.asByteHex(): MutableReactive<Byte?>
Link copied to clipboard
@JvmName(name = "writableIntAsDoubleNullable")
fun MutableReactive<Int?>.asDouble(): MutableReactive<Double?>
@JvmName(name = "writableStringAsDouble")
fun MutableReactive<String>.asDouble(): MutableReactive<Double?>
Link copied to clipboard
@JvmName(name = "writableStringAsFloat")
fun MutableReactive<String>.asFloat(): MutableReactive<Float?>
Link copied to clipboard
@JvmName(name = "writableStringAsInt")
fun MutableReactive<String>.asInt(): MutableReactive<Int?>
Link copied to clipboard
@JvmName(name = "writableStringAsIntHex")
fun MutableReactive<String>.asIntHex(): MutableReactive<Int?>
Link copied to clipboard
@JvmName(name = "writableStringAsLong")
fun MutableReactive<String>.asLong(): MutableReactive<Long?>
Link copied to clipboard
@JvmName(name = "writableStringAsLongHex")
fun MutableReactive<String>.asLongHex(): MutableReactive<Long?>
Link copied to clipboard
fun <T> MutableReactive<T>.assert(summary: String, description: String = summary, setOnIssue: Boolean = true, condition: (T) -> Boolean): MutableValidated<T>

Asserts a condition on this MutableReactive instance and reports an issue if the condition fails.

Link copied to clipboard
@JvmName(name = "writableStringAsShort")
fun MutableReactive<String>.asShort(): MutableReactive<Short?>
Link copied to clipboard
@JvmName(name = "writableStringAsShortHex")
fun MutableReactive<String>.asShortHex(): MutableReactive<Short?>
Link copied to clipboard
@JvmName(name = "writableStringAsUByteHex")
fun MutableReactive<String>.asUByteHex(): MutableReactive<UByte?>
Link copied to clipboard
@JvmName(name = "writableStringAsUIntHex")
fun MutableReactive<String>.asUIntHex(): MutableReactive<UInt?>
Link copied to clipboard
@JvmName(name = "writableStringAsULongHex")
fun MutableReactive<String>.asULongHex(): MutableReactive<ULong?>
Link copied to clipboard
@JvmName(name = "writableStringAsUShortHex")
fun MutableReactive<String>.asUShortHex(): MutableReactive<UShort?>
Link copied to clipboard
suspend fun <T> Reactive<T>.await(): T
Link copied to clipboard
suspend fun <T : Any> Reactive<T?>.awaitNotNull(): T
Link copied to clipboard
suspend fun <T> Reactive<T>.awaitOnce(): T
Link copied to clipboard
open override fun beginUse(): () -> Unit

Begins using the resource. Returns a function to stop using the resource.

Link copied to clipboard

Adds a validation check to a MutableReactive instance, returning a MutableValidated that tracks issues.

Link copied to clipboard
@JvmName(name = "containsList")
infix fun <T> MutableReactive<List<T>>.contains(value: T): MutableReactive<Boolean>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
inline suspend fun <T> Reactive<T>.exception(): Exception?
Link copied to clipboard
Link copied to clipboard
inline suspend operator fun <T> Reactive<T>.invoke(): T
Link copied to clipboard
open fun <L> lens(get: (T) -> L, set: (L) -> T): MutableReactive<L>

'Lenses' a new type from this MutableReactive. This is useful when translating one type to another for user input, or safe type coercion.

open fun <L> lens(get: (T) -> L, modify: (T, L) -> T): MutableReactive<L>

'Lenses' a subtype from this MutableReactive. This is useful for extracting properties from a data class or modifying a single item in a collection.

Link copied to clipboard
fun <T, L> Reactive<T>.lens(get: (T) -> L): Reactive<L>
Link copied to clipboard
@JvmName(name = "setLensByElement")
fun <E, ID> MutableReactive<Set<E>>.lensByElement(identity: (E) -> ID): LensByElement<E, ID, LensByElement.Element<E, ID, *>>
@JvmName(name = "setLensByElement")
fun <E, ID, W> MutableReactive<Set<E>>.lensByElement(identity: (E) -> ID, map: CalculationContext.(MutableWithReactiveValue<E>) -> W): LensByElement<E, ID, W>
Link copied to clipboard

THIS ONLY WORKS IF THE set on the receiver never manipulates the input before notifying.

Link copied to clipboard
@JvmName(name = "setLensByElementWithIdentity")
fun <E, ID> MutableReactive<Set<E>>.lensByElementWithIdentity(identity: (E) -> ID): LensByElement<E, ID, LensByElement.Element<E, ID, *>>
@JvmName(name = "setLensByElementWithIdentity")
fun <E, ID, W> MutableReactive<Set<E>>.lensByElementWithIdentity(identity: (E) -> ID, map: CalculationContext.(MutableWithReactiveValue<E>) -> W): LensByElement<E, ID, W>
Link copied to clipboard
fun <T> Listenable.lensListenable(get: () -> T): Reactive<T>
Link copied to clipboard
infix suspend fun <T> MutableReactive<T>.modify(action: suspend (T) -> T)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun <T> Reactive<T>.onNextSuccess(action: (T) -> Unit): () -> Unit
Link copied to clipboard
operator fun Listenable.plus(other: Listenable): Listenable
Link copied to clipboard
fun reset()

Restores automatic calculation and updates the value from dependencies. If the value was overridden, this resumes listening and updates the value.

Link copied to clipboard
abstract infix suspend fun set(value: T)
Link copied to clipboard
suspend fun <T> Reactive<T>.state(): ReactiveState<T>
suspend fun <T, V> Reactive<T>.state(get: (ReactiveState<T>) -> V): V
Link copied to clipboard
Link copied to clipboard
fun <T> MutableReactive<T>.validate(setOnIssue: Boolean = true, validate: (T) -> String?): MutableValidated<T>

Adds a validation check to this MutableReactive instance.

Link copied to clipboard
Link copied to clipboard
fun MutableReactive<String>.validateNotBlank(summary: String = "Cannot be blank.", description: String = summary, setOnIssue: Boolean = true): MutableValidated<String>

Validates that the value of this MutableReactive is not blank (for String values).

Link copied to clipboard
fun <T : Any> MutableReactive<T?>.validateNotNull(summary: String = "Cannot be blank.", description: String = summary, setOnIssue: Boolean = true): MutableValidated<T?>

Validates that the value of this MutableReactive is not null.

Link copied to clipboard
open infix override fun valueSet(value: T)
Link copied to clipboard
fun <T> Reactive<T>.withWrite(action: suspend Reactive<T>.(T) -> Unit): MutableReactive<T>