5 Replies Latest reply on Mar 24, 2011 3:12 AM by KapFlorian

    IntegrationLib : Potential bug with CommandResult and PM

    KapFlorian

      Hi,

       

      We are playing a bit with IntegrationRPC lib and we might have found a bug... or maybe we are doing something wrong

       

      Let's say I have a reusable component that loads a list of contacts.

      When the list is retrieved from the server, a status message appears on bottom of the component.

       

      Now imagine, I need 2 instances of this component in a view.

      Each component needs a new instance of its presentation model. This is done by setting

      singleton property to false in the context :

       

      <Object type="{ ContactsViewModel }" singleton="false" />
      

       

      ContactsViewModel listens to the SearchContactsCommand result :

       

      [CommandResult(selector="search")]
      public function searchDone(items:IList, e:Event):void
      {
               if (e.target == this)
                status = "Search Done";
      }
      

       

      The if statement is used to be sure only the "calling" PM displays the "Search Done" message.

      I know this is probably not the best way to manage reusable components in an application but this is not the point of this subject.

      (BTW, we haven't found any doc talking about this on the wiki so we are interested in best practices about it)

       

      We found that this is not working as expected!

      Only the last instancied PM gets called once the server has responded instead of each PM instance.

       

      I could attach the source code, this is just a sample application.

      However, you can observe this behaviour with the InSync demo app :

      Open 3 tabs, do some changes on the first tab and click the save button.

      Notice then that "Contact saved." is displayed on the last tab!

        • 1. Re: IntegrationLib : Potential bug with CommandResult and PM
          KapFlorian Level 1

          Has anyone looked at this issue?

          • 2. Re: IntegrationLib : Potential bug with CommandResult and PM
            Alex Uhlmann Level 3

            As Parsley 2.2 mirrored and improved Commands, we'll deprecate the Cairngorm Commands. Cairngorm Commands were only intented to be temporarily until they are native in Parsley. Have you tried that in the Parsley implementation?

            • 3. Re: IntegrationLib : Potential bug with CommandResult and PM
              KapFlorian Level 1

              Alex, I haven't tried it yet. I'll probably have a look start of next  week.

               

              ContactsViewModel listens to the SearchContactsCommand result :

               

              [CommandResult(selector="search")]
              public function searchDone(items:IList, e:Event):void
              {
                       if (e.target == this)
                        status = "Search Done";
              }
              

               

              The if statement is used to be sure only the "calling" PM displays the "Search Done" message.

              I know this is probably not the best way to manage reusable components in an application but this is not the point of this subject.

              (BTW, we haven't found any doc talking about this on the wiki so we are interested in best practices about it)

               

              Any thought about that? Reusable components are typical use-cases when developing applications

              • 4. Re: IntegrationLib : Potential bug with CommandResult and PM
                MrKoinkoin Level 1

                I may have not understood your need but could you not use "context" for this (check Parsley 2.3 doc on event handling with context) ?

                if you have to send your "getContactEvent" from two different PM type A and B and use the same Command in order to either get result back to PM A or B:

                 

                1- just create two context (contextA and contextB thru context files declared inside the MXML component you want to dispatch the event )  and declare inside these two contexts your PM and the Command associated to it.

                 

                2- Then in the PM(s) which should dispatch the event put :

                [ManagedEvents(names="getContactEvent", scope="local")]

                 

                3- Inside the Command class (which should be "shared" by your components/package/modules...) just update your method declaration with this :

                [CommandResult(selector="search", scope="local")]

                function searchDone(items:IList, e:Event):void{ ... }

                 

                In this way the event will only be dispatch thru your "local" component (the PM declared in the context) .

                 

                Of course you could also declared your variable "status" in the local context in order to use it in a "shared" way (using injection).

                 

                Hope it will help. 

                 

                Cédric

                • 5. Re: IntegrationLib : Potential bug with CommandResult and PM
                  KapFlorian Level 1

                  Yes, this is how you should do it now. Actually, this feature was not available at the time of the message ;-)

                   

                  Thanks anyway