[announce] InhiBeans: mitigate redundant recalculations

Scott Palmer swpalmer at gmail.com
Sun Dec 15 15:39:12 PST 2013


Good stuff!   This is the sort of thing that might make a good contribution
to extend the standard Bindings class.

Scott


On Sun, Dec 15, 2013 at 5:49 PM, Tomas Mikula <tomas.mikula at gmail.com>wrote:

> On Sun, Dec 15, 2013 at 6:39 PM, Scott Palmer <swpalmer at gmail.com> 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.
>
> Hi Scott,
>
> this is precisely the problem that I'm trying to address here. Now,
> the question is whether you have control over the implementation of
> obj.
>
> If yes, then it is the same case as the AND gate "motivational
> example" from InhiBeans page. You provide a method setSize(w, h) and
> use block()/release() to implement it in a way that causes only one
> change of the area property.
>
> If you cannot change the implementation of obj, what you can do is to
> bind an inhibeans.binding.DoubleBinding to the "area" value, call it
> relaxedArea, and listen to that one for all your purposes.
> Then you resize obj like this:
>
> relaxedArea.block();
> obj.setWidth();
> obj.setHeight();
> relaxedArea.release();
>
> Only one change of relaxedArea is emitted.
>
> Best,
> Tomas
>
> >
> > 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