[announce] InhiBeans: mitigate redundant recalculations

Scott Palmer swpalmer at gmail.com
Sun Dec 15 11:55:53 PST 2013


Yes, that does the trick, but this basically means you can't use bindings
for such things.  I'm wondering if there might be an opportunity for
another enhancement similar to the block() resume() that Tomas has
implemented, but for receiving size of the notification mechanism.
 Effectively it would operate on a bound property and prevent the
re-evaluation until the resume() is called.  When resume is called the
property binding would check if it was invalidated since it was blocked and
do the appropriate recalculation.  E.g. property.blockEvaluation(),
property.resumeEvaluation(), only callable on a property that is bound.  I
haven't thought it through yet, so I'm not sure if it buys much.


Scott


On Sun, Dec 15, 2013 at 2:30 PM, John Hendrikx <hjohn at xs4all.nl> wrote:

> Since you are only allowed to modify properties on the JavaFX thread (in
> most cases), I've been using Platform.runLater() to make sure I observe
> only complete changes.
>
> Basically I register an InvalidationListener on the properties that are
> relevant, and when one gets triggered I set a boolean and trigger a
> Runnable that
> will be run on the JavaFX thread later (and after the change completes).
>  The Runnable checks the relevant values and acts on them, then resets the
> boolean.
>
> I use this mechanism for example when I'm observing Objects with many
> properties that need to be stored in a database.  To make sure I only store
> consistent objects, I only observe the values of the properties when my own
> little piece of observer code runs on the JavaFX thread.  Since nothing can
> modify the properties except on the JavaFX thread, this is almost like a
> form of transactions, ensuring that every change has completed before
> observing the results.
>
> --John
>
>
> On 15/12/2013 18:39, Scott Palmer wrote:
>
>> Interesting idea.
>>
>> There is a case I have been curious about and wonder what the best
>> practices are for it.  Suppose you have a case when you are changing
>> multiple different properties that will be used in a single calculation.
>>   You want to deal with a single change to all of them in one go.  E.g.
>> imagine you have an "area" property that is bound to both "width" and
>> "height".  You want to write code like:
>>
>> obj.setWidth(w);
>> obj.setHeight(h);
>>
>> and have only ONE recalculation of the area property happen.  Currently
>> the
>> way bindings work the area will be calculated twice.  The intermediate
>> calculation is really not a value that you ever want to observe.
>>
>> Are there helpers for this sort of situation?  Are there guidelines in the
>> JavaFX docs somewhere?
>>
>> Regards,
>>
>> Scott
>>
>>
>> On Sat, Dec 14, 2013 at 11:54 PM, Tomas Mikula<tomas.mikula at gmail.com>
>> wrote:
>>
>>  Hello,
>>>
>>> I just published a small extension of javafx bindings and properties
>>> that can help you reduce redundant recalculations.
>>>
>>> They provide two additional methods:
>>>
>>> public void block();
>>> public void release();
>>>
>>> Call p.block() when you suspect your actions will lead to multiple
>>> invalidations of p, and call p.release() when you are done and want to
>>> deliver a single invalidation notification to p's observers.
>>>
>>> https://github.com/TomasMikula/InhiBeans
>>>
>>> Regards,
>>> Tomas
>>>
>>>
>


More information about the openjfx-dev mailing list