<div dir="ltr"><div>I like "when" (partly because it is short and to the point, Java is already verbose enough.)</div><div><br></div><div>I also thought of "trackWhile" to indicate the value is only tracking the value of the source ObservableValue while the condition is true.</div><div><br></div><div>Scott</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Nov 14, 2022 at 12:47 PM Andy Goryachev <<a href="mailto:andy.goryachev@oracle.com" target="_blank">andy.goryachev@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div>
<div lang="EN-US">
<div>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Courier New"">I'd pick "whenever" or "onCondition".<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Courier New"">"updateWhen" sounds like an update, which I think it is not. "when" seems too vague.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Courier New"">Disclaimer: English is not my native language.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Courier New"">-andy<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Courier New""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Courier New""><u></u> <u></u></span></p>
<div style="border-style:solid none none;border-top-width:1pt;border-top-color:rgb(181,196,223);padding:3pt 0in 0in">
<p class="MsoNormal" style="margin-bottom:12pt"><b><span style="font-size:12pt;color:black">From:
</span></b><span style="font-size:12pt;color:black">openjfx-dev <<a href="mailto:openjfx-dev-retn@openjdk.org" target="_blank">openjfx-dev-retn@openjdk.org</a>> on behalf of Kevin Rushforth <<a href="mailto:kevin.rushforth@oracle.com" target="_blank">kevin.rushforth@oracle.com</a>><br>
<b>Date: </b>Monday, 2022/11/14 at 09:40<br>
<b>To: </b><a href="mailto:openjfx-dev@openjdk.org" target="_blank">openjfx-dev@openjdk.org</a> <<a href="mailto:openjfx-dev@openjdk.org" target="_blank">openjfx-dev@openjdk.org</a>><br>
<b>Subject: </b>Re: Discussion: Naming API method<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12pt"><span style="font-size:11pt">I also think this will be a useful feature to get into JavaFX.<br>
<br>
As for the name of the method, the only one of them I don't like is <br>
"conditionOn". That name doesn't suggest (to me anyway) what its purpose <br>
is. I think any of the ones with "when" in the name would work. I have a <br>
slight preference for "updateWhen", but could be talked into one of the <br>
others.<br>
<br>
-- Kevin<br>
<br>
<br>
On 11/14/2022 6:52 AM, John Hendrikx wrote:<br>
> Hi,<br>
><br>
> I'm working on <a href="https://github.com/openjdk/jfx/pull/830" target="_blank">https://github.com/openjdk/jfx/pull/830</a> where I asked
<br>
> for some opinions on the naming of a new method I'd like to introduce <br>
> in ObservableValue.<br>
><br>
> I wrote a (perhaps too large) comment about the possible names and <br>
> rationales: <br>
> <a href="https://github.com/openjdk/jfx/pull/830#issuecomment-1304846220" target="_blank">https://github.com/openjdk/jfx/pull/830#issuecomment-1304846220</a><br>
><br>
> I'd like to ask what others think what would be a good name for this <br>
> new method (Observable#when in the PR) in order to move the PR <br>
> forward, as I think it offers a very compelling feature to JavaFX <br>
> (moving from weak reference to deterministic behavior when it comes to <br>
> listener management). My opinion has always been that using weak <br>
> listeners for listener management is a crutch that relies far too much <br>
> on the internal workings of the JVM and Garbage Collector which offer <br>
> no guarantees as to the timely clean up of these references and the <br>
> listeners related to them.<br>
><br>
> Leading contenders are (but not limited to these, if you have a better <br>
> name):<br>
><br>
> 1) conditionOn<br>
><br>
> 2) updateWhen<br>
><br>
> 3) when<br>
><br>
> 4) whenever<br>
><br>
> Usage in code is nearly always going to be something like these <br>
> constructs:<br>
><br>
> // keeps text property in sync with longLivedProperty when label <br>
> is shown:<br>
> label.textProperty().bind(longLivedProperty.**when**(label::isShownProperty)); <br>
><br>
><br>
> // keeps text property in sync with longLivedProperty when <br>
> container is shown:<br>
> label.textProperty().bind(longLivedProperty.**when**(container::isShownProperty));
<br>
><br>
><br>
> It can also be used to make a listener only actively listen when a <br>
> condition is met (the listener is added/removed immediately when the <br>
> condition changes, facilitating GC):<br>
><br>
> // listen to changes of longLivedProperty when container is shown:<br>
> longLivedProperty.when(container::isShownProperty)<br>
> .addListener((obs, old, current) -> { ... change listener <br>
> ... });<br>
><br>
> Or it can be used to disable updates temporarily (or permanently):<br>
><br>
> BooleanProperty allowUpdates = new SimpleBooleanProperty(true)<br>
><br>
> // keeps text property in sync when updates are allowed:<br>
> name.textProperty().bind(model.title.when(allowUpdates));<br>
> detail.textProperty().bind(model.subtitle.when(allowUpdates));<br>
> asyncImageProperty.imageHandleProperty().bind(model.imageHandle.when(allowUpdates));
<br>
><br>
><br>
> This last example can be useful in Skin#dispose, but has uses outside <br>
> of skins as well, for example when you want to prevent updates until <br>
> things have settled down.<br>
><br>
> Thanks for reading!<br>
><br>
> --John<br>
><br>
><u></u><u></u></span></p>
</div>
</div>
</div>
</div></blockquote></div>