On Mon, 8 Feb 2021 13:42:52 GMT, Ambarish Rapte <ara...@openjdk.org> wrote:

>> Isn't it quite error prone to repeat this logic again (especially with all 
>> the null cases), not to mention that you would need to test the code for the 
>> initial case (with/without Scene, with/without Window), the "in use" case 
>> and again for the disposal case?
>> 
>> I personally use helpers for this kind of property chaining as it is far to 
>> easy to get wrong:
>> 
>>     public Binding<Boolean> isShowing(Node node) {
>>         Values.of(node.sceneProperty())
>>            .flatMap(s -> Values.of(s.windowProperty()))
>>            .flatMap(w -> Values.of(w.showingProperty()))
>>            .orElse(false)
>>            .toBinding();
>>     }
>> 
>> The implementation here takes care of `null` and automatically tracks 
>> property changes and is type safe to boot.  I think JavaFX in general could 
>> really benefit from this, as I've seen this chaining logic repeated a lot.
>
> My concern is about having a similar way of doing something. It would keep 
> the code uniform. We have been following the earlier pattern under a cleanup 
> task [JDK-8241364](https://bugs.openjdk.java.net/browse/JDK-8241364). Several 
> bugs under this task are being fixed in earlier way.
> May be we can discuss the new way of handling properties under a separate 
> issue and plan to modify all such instances at once. Does that sound ok ?

hmm ... might appear convenient (in very controlled contexts) but looks like a 
precondition violation: the sender of the change must not be null (concededly 
not explicitly spec'ed but logically implied, IMO)

so would tend to _not_ see this as blueprint for a general pattern fx code base

-------------

PR: https://git.openjdk.java.net/jfx/pull/185

Reply via email to