Export to GitHub

bindage-tools - issue #18

IPipelineBuilder method to set up binding without running it now.


Posted on Sep 23, 2011 by Happy Dog

When setting up two-way bindings, the standard behavior is to set up listeners on both model and UI for each binding, but only run the model-to-UI binding now.

When setting two-way up bindings with multiple sources/destinations, this is hard to achieve:

var fooGroup = new BindGroup();

// model to UI bindings Bind.fromProperty(model, 'foo') .group(fooGroup) .convert(toCondition(notNullValue())) .toProperty(fooCheckbox, 'selection');

Bind.fromProperty(model, 'foo.description') .group(fooGroup) .toProperty(fooInput, 'text');

// reciprocal UI to model binding

Bind.fromAll( Bind.fromProperty(fooCheckbox, 'selection), Bind.fromProperty(fooInput, 'text') ) .group(fooGroup) .convert(function(checked:Boolean, description:String):Foo { return checked ? new Foo(description) : null; }) .toProperty(model, 'foo');

The problem with this setup is that because the UI-to-model binding runs immediately, the model can occasionally be clobbered by UI defaults due to the component invalidation cycle.

This issue is to add new methods to IPipelineBuilder which set up a pipeline and its listeners, but does not execute the binding right now.

Bind.fromAll( Bind.fromProperty(fooCheckbox, 'selection), Bind.fromProperty(fooInput, 'text') ) .group(fooGroup) .convert(function(checked:Boolean, description:String):Foo { return checked ? new Foo(description) : null; }) .toPropertyOnNextChange(model, 'foo');

There would also be an equivalent IPipelineBuilder.toFunctionOnNextChange() function.

Comment #1

Posted on Jan 20, 2012 by Happy Dog

After some discussions at work, changing the target API as follows:

Bind.nextTime() .fromAll( Bind.fromProperty(fooCheckbox, 'selection), Bind.fromProperty(fooInput, 'text') ) .group(fooGroup) .convert(function(checked:Boolean, description:String):Foo { return checked ? new Foo(description) : null; }) .toPropertyOnNextChange(model, 'foo');

Also considering adding a top-level function bind() which returns an IPipelineBuilderFactory, containing all the methods in Bind. Thus:

bind().nextTime().fromProperty(model, "foo").toProperty(fooInput, "text");

Comment #2

Posted on Jan 20, 2012 by Happy Dog

Note that the new bind() top-level function--assuming it works out well--would render the Bind class obsolete and that we would probably deprecate and remove it later on.

Comment #3

Posted on Jan 20, 2012 by Happy Dog

Changeset 50a73fcfecc5: work in progress

Added bind() top-level function, IPipelineBuilderFactory interface, PipelineBuilderFactory implementor class, and moved implementations from Bind to PipelineBuilderFactory.

Comment #4

Posted on Jan 23, 2012 by Happy Dog

Changeset 2ff9da99777f: added unit tests

Comment #5

Posted on Jan 26, 2012 by Happy Dog

Fixed

Status: Fixed

Labels:
Type-Enhancement Priority-Medium Milestone-0.0.6