ReadOnlyPropertyDefaultObservable

class ReadOnlyPropertyDefaultObservable<R : T?, T>(defaultValue: R, readOnlyProperty: ReadOnlyProperty<Any?, T>, observation: ObservationDefault<R, T?> = ObservationDefault( defaultValue, ObservableOptional.Value( run { val v by readOnlyProperty v }, ), )) : BaseDefaultObservable<R, T>

A BaseDefaultObservable that matches its value to a ReadOnlyProperty. When the ReadOnlyProperty updates, changes to the property are not immediately delegated back to the observable. Use a Flow based observable if synchronized values are required

Parameters

T

the type of value to expect.

R

the type of result to expect. Must be a subclass of T

defaultValue

The default R to return if the value of the ReadOnlyProperty is null.

readOnlyProperty

The ReadOnlyProperty to track.

observation

The ObservationInitialized to handle observation.

Constructors

Link copied to clipboard
constructor(defaultValue: R, readOnlyProperty: ReadOnlyProperty<Any?, T>, observation: ObservationDefault<R, T?> = ObservationDefault( defaultValue, ObservableOptional.Value( run { val v by readOnlyProperty v }, ), ))

Properties

Link copied to clipboard
open override val current: R

The current value of R

Link copied to clipboard
open override val currentOrNull: T?

The current value T or null being observed

Link copied to clipboard

The default Value of R. Can be used in case Nothing is Initial.initialValue

Link copied to clipboard

The initial ObservableOptional value of T.

Link copied to clipboard
expect open override val stateFlow: StateFlow<R>

StateFlow that expresses the content from the observable.

Link copied to clipboard
expect open override val valueDelegate: ReadOnlyProperty<Any?, R>

Functions

Link copied to clipboard
open operator override fun getValue(thisRef: Any?, property: KProperty<*>): ObservableOptional.Value<R>
Link copied to clipboard
open override fun observe(onNext: (R?) -> Unit): Disposable

Creates an observation that calls onNext each time a new value is observed until the resulting Disposable is disposed

Link copied to clipboard
open override fun observeInitialized(onNext: (R) -> Unit): Disposable
Link copied to clipboard
fun <T> WithState<T?>.observeNotNullOnLifecycle(lifecycleOwner: LifecycleOwner, filter: suspend (T) -> Boolean = { true }, onNext: (T) -> Unit): Job

Observes WithState of a nullable value on the lifecycle of a LifecycleOwner

Link copied to clipboard
fun <T> WithState<T>.observeOnLifecycle(lifecycleOwner: LifecycleOwner, filter: suspend (T) -> Boolean = { true }, onNext: (T) -> Unit): Job

Observes WithState on the lifecycle of a LifecycleOwner

fun <T, R> WithState<T>.observeOnLifecycle(lifecycleOwner: LifecycleOwner, filter: suspend (T) -> Boolean = { true }, transform: suspend (T) -> R, onNext: (R) -> Unit): Job

Observes WithState on the lifecycle of a LifecycleOwner by transforming the observed value.