The API should be intuitive to use and address issues currently seen in JavaFX requiring weak listeners and the storing of references to intermediate bindings to make sure they don't get garbage collected. This will be resolved by introducing lazy bindings in a derivative class of ObjectBinding called LazyObjectBinding.
Lazy bindings in effect are always invalid when not themselves observed. This allows for easier garbage collection (once the last observer is removed, a chain of bindings will stop observing their parents severing the hard reference from parent to child) and less listener management when dealing with nested properties.
Lazy bindings will also allow the safe inclusion of derived properties in top level classes like Node without causing listeners to be created for every Node created (increasing memory consumption and time spent on listener management), as long as these derived properties are not in actual use.
This ticket addresses JDK-8091544 which is a feature request for type a safe alternative to Bindings#select. It also provides arbitrary conversion of bindings which addresses JDK-8091316.
A PoC can be found here: https://github.com/openjdk/jfx/pull/434 and here https://github.com/openjdk/jfx-sandbox/tree/jfx-sandbox/nlisker_fuent_bindings
For a minimal implementation the following new public API should be introduced in ObservableValue:
- map: Returns an ObservableValue which holds a mapping of the value held by this ObservableValue, and is null when this ObservableValue null
- flatMap: Returns an ObservableValue which holds the value in the ObservableValue given by applying a mapper on the value of this ObservableValue, and is null when this ObservableValue is null.
- orElse: Returns an ObservableValue}which holds a mapping of the value held by this ObservableValue, or the value held by alternativeValue when this ObservableValue is null
- csr for
-
JDK-8277456 Map, FlatMap and OrElse fluent bindings for ObservableValue
- Closed
- duplicates
-
JDK-8206449 ObjectBinding should clear internal value when invalidated to avoid leak
- Closed
- relates to
-
JDK-8290038 Improve documentation for the referencing model of bindings and listeners in combination with GC
- Open
-
JDK-8290037 Bindings should clean up after themselves when their weak listeners go out of scope
- Open
-
JDK-8290040 Provide simplified deterministic way to manage listeners
- Resolved
-
JDK-8290331 Binding value left null when immediately revalidated in invalidation listener
- Resolved
-
JDK-8291552 Select binding not updated correctly in JavaFX 19-ea+9
- Closed
-
JDK-8091316 Add a Bindings.map() method
- Open
-
JDK-8091544 Bindings.select*(): add new type-safe template based API instead of legacy-style set of methods
- Open