RFR: JDK-8303897 ObservableValue's when binding should only invalidate when strictly needed [v2]
John Hendrikx
jhendrikx at openjdk.org
Sun Apr 9 20:56:02 UTC 2023
On Sun, 9 Apr 2023 20:48:50 GMT, John Hendrikx <jhendrikx at openjdk.org> wrote:
>> modules/javafx.base/src/test/java/test/javafx/beans/value/ObservableValueWhenTest.java line 139:
>>
>>> 137: property.when(condition)
>>> 138: .map(x -> { observedMappings.add(x); return x; })
>>> 139: .addListener((obs, old, current) -> observedChanges.add(old + " -> " + current));
>>
>> What do you think about a variant with an invalidation listener?
>
> That's not really useful as there is no way to make such a fluent binding valid again (it would invalidate once, and never become valid). The only way to make it valid would be to assign the result of `map` to a variable, and call `get` on that.
>
> I can however add a test that proves the above :)
Also, the test is specifically looking how often `map` is called here (which is triggered by invalidations from the `when`). The listener is only there to make sure that `map` has installed its listeners as fluent observables don't install them when not observed themselves. I could have used an `InvalidationListener` here for this purpose, but then I'd still need to call `getValue` on the `map` observable as otherwise it will definitely not map anything as it is invalid.
Perhaps a simple test that shows this is the case can be useful.
-------------
PR Review Comment: https://git.openjdk.org/jfx/pull/1056#discussion_r1161339789
More information about the openjfx-dev
mailing list