RFR: 8274771: Map, FlatMap and OrElse fluent bindings for ObservableValue [v14]
John Hendrikx
jhendrikx at openjdk.java.net
Tue Mar 22 14:26:52 UTC 2022
On Tue, 22 Mar 2022 12:38:43 GMT, yosbits <duke at openjdk.java.net> wrote:
> This PR is considered a design change that delegates multiple responsibilities to the basic JavaFX class ObservableValue. The balance between implementation complexity and convenience seems to be a point of contention.
If you could do a review and voice your concerns, I'd be happy to see if they can be addressed. I would also like to point out that it is an addition to the current API and does not affect any of the current ways of using JavaFX. In that regard it is like Streams and Optional, something you can choose not to use.
I'm just not entirely sure what you want to say with your earlier example. If we remove null safety, then the example:
label.textProperty().bind(
employee.map(Employee::getCompany)
.map(Company::getName)
.orElse("")
);
Would then be forced to become something like (or the `Optional` equivalent):
label.textProperty().bind(
employee.map(e -> e == null ? null : e.getCompany())
.map(c -> c == null ? "" : c.getName())
);
As JavaFX object properties can often be `null` and are `null` by default, this is a pretty easy way to get an NPE which I think would make sense to avoid.
Also I'm unsure what you mean by implementation complexity, I think it is far less complex than some pieces of code I've seen in the JavaFX codebase (View classes, Layout code, Label reflow calculations) and I think is much better separated and structured than any of those. If you could point out any problems perhaps we can still address them. Excluding test code the change is really rather minimal, perhaps 200-300 actual lines of code.
The most tricky part is perhaps the lazy binding aspect, but that's also the part that will offer the most convenience for users as there is no more need to rely on unpredictable weak bindings (a GC will not clean up bindings unexpectedly).
-------------
PR: https://git.openjdk.java.net/jfx/pull/675
More information about the openjfx-dev
mailing list