bind

fun bind(callback: (T) -> Unit? = null): DisposableHandle(source)

Binds a callback to this observable property.

The provided callback will be invoked immediately with the current state of the property when this function is called. Subsequently, the callback will also be invoked whenever the property's state is updated via the setValue method.

This method sets the internal onBindCallback. If a previous callback was set by this method, it will be replaced.

Return

A DisposableHandle that can be used to remove the registered callback. Calling dispose() on the returned handle will clear the callback only if it is the same callback instance that was originally passed to this bind function. This prevents accidental removal of callbacks set by other parts of the code.

Parameters

callback

An optional lambda function that takes the new value of type T as input and returns Unit. If null, any existing bound callback will be cleared.