Binding0

class Binding0<E : Any, T : Any>(program: Program, val element: Element, val event: Event<E>, val property: KMutableProperty0<T>, newValueFromEvent: (E) -> T, setElementValue: (T) -> Unit) : AutoCloseable(source)

A utility class for bi-directionally binding a property of type T to an Element, where changes in one are synchronized with the other. The binding operates on the provided Program instance's coroutine scope and listens for events of type E, which are used to update the property value.

Parameters

E

The type of the input event used for updating the property.

T

The data type of the property being bound.

program

The program instance managing the coroutine lifecycle for this binding.

element

The UI element associated with this binding.

event

The event to listen to for changes triggering property updates.

property

A mutable property reference to bind to the element value.

newValueFromEvent

A lambda function that converts the event of type E into a new property value of type T.

setElementValue

A lambda function that updates the element with the current property value.

This class continuously monitors changes to the bound property and the associated element:

  • When an E event is captured, it invokes newValueFromEvent to compute a new property value. If the value has changed, the property is updated, and the change is propagated to the element.

  • Concurrently, it checks for any modifications in the property value, ensuring the changes reflect back onto the UI element using setElementValue.

The binding operates until closed explicitly using the close method, or if the parent element is disposed.

Implements AutoCloseable to ensure proper cleanup of resources like coroutines and event listeners.

Properties:

  • currentValue maintains the current state of the bound property.

  • closed indicates whether the binding has been closed.

Closing the binding stops its coroutine, removes event listeners, and marks it as inactive.

Constructors

Link copied to clipboard
constructor(program: Program, element: Element, event: Event<E>, property: KMutableProperty0<T>, newValueFromEvent: (E) -> T, setElementValue: (T) -> Unit)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val event: Event<E>
Link copied to clipboard

Functions

Link copied to clipboard
open override fun close()