Export to GitHub

bindage-tools - issue #10

Ability to specify event types in custom binding properties


Posted on May 28, 2011 by Happy Dog

BindageTools supports binding from properties, but not for events. There are many properties (e.g. in core flash) where property changes fire and event, but we cannot react to them because there is no [Bindable] magic in core Flash. Moreover there are some situations where you just want to react to an event and do something more complicated than just call a function.

This proposal is to add a method Bind.fromEvent(source:IEventDispatcher, eventType:String) which would register on a single source object. The pipeline would receive the event object that was dispatched by the source object.

In scenarios with several binding sources, the event source would simply provide null to the pipeline if the pipeline was not initiated by that event.

One thing we would have to change to accommodate this feature is how we do cleanup. Currently we only have BindTracker.collect(Function) which only works with ChangeWatcher. This will not work for vanilla event listeners.

My current thinking is to: * Have BindTracker.collect return some other object than ChangeWatcher, possibly our own interface type, with a single method that removes the change watchers / listeners. * Return an array of functions that unwatch everything. * Return a mixed array of ChangeWatcher and dynamic objects with unwatch function members for those few elements that watch events. The user could still call unwatch() on each element, but would have to use duck typing instead of referencing the ChangeWatcher class.

I haven't decided which way to go yet. I welcome any feedback.

Comment #1

Posted on Feb 27, 2012 by Happy Dog

(No comment was entered for this change.)

Comment #2

Posted on Feb 27, 2012 by Happy Dog

Committed changeset 2e7f8adb69ec: experimental prototype

Comment #3

Posted on Mar 6, 2012 by Happy Dog

The current prototype adds support for two new possible scenarios for custom properties:

Specify property name and events to listen for:

var fooProperty = { name : "foo", events : ["fooChanged"] }

Specify property getter and events to listen for:

function getterFunction(foo:Foo):* { return ... } var fooProperty = { getter : getterFunction, events : ["fooChanged"] }

Comment #4

Posted on Mar 12, 2012 by Happy Dog

(No comment was entered for this change.)

Status: Fixed

Labels:
Type-Enhancement Priority-Medium Milestone-0.0.6