ObservableProperty

open class ObservableProperty<T>(state: MutableState<T>, onUpdated: (T) -> Unit? = null)(source)

A generic observable property that allows for value observation and modification.

This class encapsulates a value of type T and provides mechanisms to:

  • Get and set the value.

  • Register listeners that are notified before or after the value changes.

  • Bind to a callback that is invoked when the value changes or when the binding is established.

It uses a MutableState to manage the underlying state, making it compatible with Compose's state management system.

Parameters

T

The type of the value held by this observable property.

Inheritors

Constructors

Link copied to clipboard
constructor(state: MutableState<T>, onUpdated: (T) -> Unit? = null)

Functions

Link copied to clipboard
fun bind(callback: (T) -> Unit? = null): DisposableHandle

Binds a callback to this observable property.

Link copied to clipboard
fun getState(): T

Retrieves the current value of the observable property.

Link copied to clipboard
fun registerAfterChangeUpdateListener(onValueUpdateListener: (T, T) -> Unit): DisposableHandle

Registers a listener that is notified after the value of this property has changed.

Link copied to clipboard
fun registerBeforeChangeUpdateListener(onValueUpdateListener: (T, T) -> Boolean): DisposableHandle

Registers a listener that is invoked before the property's value changes.

Link copied to clipboard
fun setState(value: T)

Sets the value of the observable property using property delegation. This is a convenience method that delegates to MutableState.setValue.

Link copied to clipboard
fun setValue(value: T)

Sets the value of the observable property.

fun setValue(thisRef: Any?, prop: KProperty<*>, value: T)
Link copied to clipboard
fun setValueSilence(value: T)

Sets the value of the property without invoking the beforeChange and afterChange listeners. However, the onUpdated callback (if set) and onBindCallback callback will still be triggered.