3 Replies Latest reply on Dec 15, 2009 2:08 AM by Shivik

    Communicate between responders and events in Cairngorm

    Shivik

      Hello all

       

      I am implementing presentation model pattern in Cairngorm. Now I generally separate the responder from command classes for the sake of dividing the responsibilities - command basically set the properties on model & execute sequence commands (if any), while responders handle the task of acting on the response received from server side.

       

      But I have a scenario where I have defined a callback function in my event class and need to call it in the responder. How can I do that? Does the responder have any idea which event triggered the whole process? If yes, how can it refer that particular event class and its methods/properties?

       

      Can somebody help me out here?

       

      With best regards

      ShiVik

        • 1. Re: Communicate between responders and events in Cairngorm
          paul.williams Level 4

          You'll have to pass this information into your responder when you create it in your command. You could pass the event into the responder's constructor, or just pass in the callbacks.

          1 person found this helpful
          • 2. Re: Communicate between responders and events in Cairngorm
            Shivik Level 1

            Thanks Paul.

             

            I have basically understood the cairngorm workflow and the presentation model. I have implemented Cairngorm quite easily in many of my views. But the problems were there to see as you mentioned in your blogs about presentation patterns. Since then, I have been seeking out best practices using presentation model. But it keeps on giving me a hard time.

             

            Sometimes it just doesn't seem worth it. Like I had created a loginState property in modelLocator to manage the view states in a login screen app. The states were ERROR, LOGGED_IN, LOGGED_OUT. The view was bound directly to modelLocator's property.

             

            But when I thought about implementing it in presentation model, I could think about following things:

            • Creating a viewState property in presentation model for the view.
            • Binding the view to the property in presentation model. Till here everything goes smoothly.
            • When I update the loginState of modelLocator, I also need to update viewState of presentation model????
            • To update the viewState of presentation model, I need to create a callback function in presentation model.
            • I need to update the event as shown in this example and update the instance of that event, but what do I pass as reference to callback function?

             

            Too much going on for me to pickup.

             

            With best regards

            ShiVik

            • 3. Re: Communicate between responders and events in Cairngorm
              Shivik Level 1

              My problem here is this....

               

              • I have a Main.mxml which has three components
                1. login page - for LOGGED_OUT state
                2. login error page - for LOGIN_ERROR state
                3. member page - for LOGGED_IN state
              • The Main.mxml has a presentation model, which manages the viewState property, which controls the display of the 3 components above
              • Every component has a presentation model of its own which call the various events like LoginEvent, LogoutEvent etc.
              • I need to update the viewState property of Main.mxml using a callback, but how will I call it? It is stored in the presentation model of a view (Main.mxml) which did not trigger the particular event that received the response - which is LoginEvent of Login page.

               

              I am way over my head with this.

               

              ShiVik