Flex Mate - PropertyInjector fired twice when mapped between Manager and View

269 views Asked by At

My application uses Flex 4 and Mate framework 0.9.1. I'm facing an issue with the PropertyInjector being fired twice when there's a mapping between a manager and a view.

I have not shared the original code here, but it looks similar to the following: Based on an event, a property (someData) in MyManager is updated. A property injector updates this new value in a target view (MyView). The issue is - when onDataChanged is invoked and the property someData is updated, the method "set someData" in the view is fired twice. I know that the view is instantiated only once because I have debugged the init and creationComplete events. The source property in MyManager is also updated only once as per the trace.

This would indicate that the property injector is fired twice. Would anyone know under what conditions this can happen? Any pointers would be appreciated!

MyEventMap.mxml

    <EventHandlers type="{DataChangedEvent.GET}" debug="true">
        <MethodInvoker generator="{MyManager}" method="onDataChanged"
                   arguments="{[event.x,event.y,event.name]}">

        </MethodInvoker>
    </EventHandlers>


    <Injectors target="{MyView}" debug="true"> 
        <PropertyInjector targetKey="someData" source="{MyManager}"
                       sourceKey="someData">

        </PropertyInjector>
    </Injectors>

DataHolder.as

public class DataHolder
{
    public function DataHolder()
    {
    }
    public var x:Number;
    public var y:Number;
    public var name:String;
}

MyManager.as

public class MyManager extends EventDispatcher
{
    ....

    [Bindable] public var someData:DataHolder;

    public function onDataChanged(x:Number,y:Number,name:String):void{
        trace("dataChanged");
        var temp:DataHolder = new DataHolder();
        temp.name=name;
        temp.x=x;
        temp.y=y;
        someData = temp;    

    }
}

MyView.mxml

public function set someData(data:DataHolder):void {
    trace("setSomeData x="+data.x+",y="+data.y+",name="+data.name);
}
1

There are 1 answers

0
Arvind On

I found the problem is due to a combination of BabelFX 2.0 and Mate framework 0.9.1. Below is the BabelFX related code. Using MyView as a target of the ResourceInjector causes all PropertyInjector's related to it being fired twice. Is there an issue in the code below?

testLocalization.mxml:

<?xml version="1.0" encoding="utf-8"?>
<LocaleMap  enableLog="true"
        xmlns="http://l10n.babelfx.org/" 
        xmlns:mx="http://www.adobe.com/2006/mxml" 
        xmlns:factory="mx.core.*" >

<mx:Metadata>
    [ResourceBundle("testprop")]
</mx:Metadata>

<ResourceInjector bundleName="testprop" target="{MyView}">
    <ResourceSetter property="myButton.label" key="testsomething.title"/>
</ResourceInjector>

MyView.mxml (also the main app)

 <?xml version="1.0" encoding="utf-8"?>
 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:local="*"
           xmlns:mate="http://mate.asfusion.com/">

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    <mate:Debugger level="{Debugger.ALL}" />
    <local:testLocalization/>
    <local:MyEventMap/>

</fx:Declarations>
<s:Button id="myButton">

</s:Button>

 </s:Application>

testprop.properties

testsomething.title = SOMETHING