Spicefactory Forum Index Spicefactory
Forum Archive
 
 SearchSearch    Log inLog in 

Decoupled bindings not working with [Bindable(event="type")]

 
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory
View previous topic :: View next topic  
Author Message
rattkin



Joined: 10 May 2011
Posts: 154
Location: Poznan, PL

PostPosted: Wed Jun 19, 2013 12:58 pm    Post subject: Decoupled bindings not working with [Bindable(event="type&q Reply with quote

So a developer in my team recently created a variable in a managed object :

Code:
[Bindable(event="customChangeEvent")]
public var customVar:String;


In other function of this managed object, this event is dispatched (whole class is Event Dispatcher) as

Code:
dispatchEvent(new Event("customChangeEvent"));


We've discovered that if we use Publish / Subscribe, it suddenly stops working and the value change isn't propagated to Subscribers when the custom event is dispatched. When looking into logs, both publishes and subscriber are registered and the value is initialized and updated at the beginning but later, when the custom event is dispatched, nothing shows in log.

We've figured out that if we use bindable getter instead of variable, it will work.

Code:
[Bindable(event="customChangeEvent")]
public function get customVar():String {}


Nothing special in architecture, just two managed objects in subcontext, the same scope, one publishes, one subscribes. We use mxml declarations, so we have lines like :
Code:

<parsley:Publish property="customVar" objectId="customVarBinding" />
(...)
<parsley:Subscribe property="customVar" objectId="customVarBinding" />


I realize that using custom event with bindable and no getters/setters might be somewhat unusual, but I'm really curious why it's not working? I couldn't spot anything in the code that would help me with figuring this out. In MXML, this kind of binding works (value is updated when event is dispatched). I've seen some 3.1 TODO notes referencing to "black magic" :) - maybe that's the case?
_________________
Sebastian Zarzycki
Feerie Software
Back to top
View user's profile Send private message
rattkin



Joined: 10 May 2011
Posts: 154
Location: Poznan, PL

PostPosted: Wed Jun 19, 2013 11:30 pm    Post subject: Reply with quote

Ok, I've figured this one out, with a kind help of my friend, Mateusz Juszkiewicz. Nothing wrong with Parsley, the blame is on the usual suspect... sadly: Flex.

The code in question is FlexPropertyWatcher, added by FlexSupport :

https://github.com/spicefactory/Parsley-Core/blob/master/src/flex/org/spicefactory/parsley/flex/binding/FlexPropertyWatcher.as

As we can see, it uses BindingUtils.bindSetter, which then uses ChangeWatcher deep down. ChangeWatcher when set up for a custom event on a bindable property, simply ... doesn't work.

Apparently, it's a Flex bug/shortcoming, described here : http://www.nimblenogginsoftware.com/development/changewatcher-watch-out

Basically, when you annotate a variable with custom bindable event, it is not taken into consideration when hooking up ChangeWatchers. This can be seen directly in ChangeWatcher code:

https://git-wip-us.apache.org/repos/asf?p=flex-sdk.git;a=blob;f=frameworks/projects/framework/src/mx/binding/utils/ChangeWatcher.as;h=6e07abaff785f89d033f376d4f9c4915d4cc3218;hb=HEAD

Upon creating, it calls reset and it eventually leads to mx.binding.BindabilityInfo.getChangeEvents :

https://git-wip-us.apache.org/repos/asf?p=flex-sdk.git;a=blob;f=frameworks/projects/framework/src/mx/binding/BindabilityInfo.as;h=5cbf6ef8e58983937a5a1939e14d6e22839bdb8b;hb=HEAD

and there, it's clear that it only takes accessors and methods into consideration. Because I've used a variable (so, not accessor or method), it was simply omitted. Why it's exactly like this, no idea, but I'm really amazed that I've learned this after so many years.

As you can see, the author of that blog figured out the very same solution, by trial/error - just use a custom getter (accessor).
_________________
Sebastian Zarzycki
Feerie Software
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group