Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Is it ok for a mediator to make calls like this?  (Read 10626 times)
Helmut Granda
Full Member
***
Posts: 47

Flash Developer.


View Profile WWW Email
« on: September 24, 2009, 12:53:00 »

//in ApplicationMediator

      override public function handleNotification(notification:INotification):void 
        { 
            var name:String = notification.getName(); 
            var body:Object = notification.getBody(); 

            switch ( name ) 
            { 
                case BrowserProxy.DATA_READY:
               var setingsProxy : SettingsProxy = facade.retrieveProxy ( SettingsProxy.NAME ) as SettingsProxy ;
               setingsProxy.settingsDataGet();
                break; 
      
            } 
        }

The ApplicationMediator is the only one who cares if the Browser Settings have been set. Once that is completed then we need to make a new call to SettingsProxy to get information from a XML.

Again this works perfectly but I am wondering about this in regards to best practice.
Logged
isragaytan
Full Member
***
Posts: 22


View Profile Email
« Reply #1 on: September 24, 2009, 04:11:22 »

I think the best way to do it to put the call in a Command. As i said before its much cleaner and a best practice so in my own opinion....

 You could do something like this:

:
override public function handleNotification(notification:INotification):void
        {
            var name:String = notification.getName();
            var body:Object = notification.getBody();

            switch ( name )
            {
                case BrowserProxy.DATA_READY:
                     sendNotification(ApplicationFacade.SETTINGS_DATA_GET);
                break;
     
            }
        }



Now in somewhere else you have to register your command , may be in the ApplicationFacade..now

...your Command..

:

override public function execute(notification:Inotification):void{

      var setingsProxy : SettingsProxy = facade.retrieveProxy ( SettingsProxy.NAME ) as SettingsProxy ;
               setingsProxy.settingsDataGet();
       }       

}




and the last thing send another notification of the proper proxy for data retrieved.

Hope it helps...

Cheers
Logged
Helmut Granda
Full Member
***
Posts: 47

Flash Developer.


View Profile WWW Email
« Reply #2 on: September 24, 2009, 07:23:56 »

Thank you for your comments Isragaytan. ( o como diriamos en otros lados. Muchas gracias! :) ).
Logged
Helmut Granda
Full Member
***
Posts: 47

Flash Developer.


View Profile WWW Email
« Reply #3 on: September 24, 2009, 08:05:13 »

Ok, so now I have it all working nicely and is getting better by the minute, but I just realized that I have one DataCommand that is registered with Multiple Proxies.

:
registerCommand ( SettingsProxy.GET_DATA, DataCommand ) ;
registerCommand ( SettingsProxy.DATA_READY, DataCommand ) ;
registerCommand ( BrowserProxy.GET_DATA, DataCommand ) ;
registerCommand ( BrowserProxy.DATA_READY, DataCommand ) ;

The only draw back that I see on this is that my DataCommand can become quite large when it has to manipulate large blocks of information, in which case I was thinking of breaking it into smaller commands.

:
registerCommand ( SettingsProxy.GET_DATA, SettingsCommand ) ;
registerCommand ( SettingsProxy.DATA_READY, SettingsCommand ) ;
registerCommand ( BrowserProxy.GET_DATA, BrowsserCommand ) ;
registerCommand ( BrowserProxy.DATA_READY, BrowserCommand ) ;

I guess with a small application the first option is ok but as the application becomes larger then the latter would be preferred.

Thoughts?
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #4 on: September 25, 2009, 06:18:35 »

Your first solution is acceptable, and often the preferred, solution. Mediators can talk directly with Proxies for simple gets and sets. I only use commands when I need to transform data before sending it to the view, or when I need to perform any action that will be called from multiple Mediators. When you simply want to check for a boolean value being set or do a direct pull of data, a command is overkill. Just have the Mediator call the Proxy directly.

For the second question, I think the same applies. If you are not transforming or manipulating the data, then just call you getData() method from the Mediator. You'll quickly become bogged down with commands if you try to funnel every single interaction through them (Cairngorm anyone?). Commands are better used for complex operations or things that will be reused by mutiple actors.
« Last Edit: September 25, 2009, 06:24:59 by Jason MacDonald » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: September 25, 2009, 07:02:59 »

While it's perfectly fine to locate that sort of thing in a Command (ala Cairngorm), you really only need to do that if that same code will be triggered from multiple places.

As Jason mentioned it is perfectly acceptable for a Mediator to access and update Proxies. In fact the code you had to begin with would be correct except that usually, we have the Mediator retrieve the reference to the Proxy in the onRegister method and keep it on a private local variable. That way it only has to be retrieved once and not each time the notification is sent.

-=Cliff>
Logged
Helmut Granda
Full Member
***
Posts: 47

Flash Developer.


View Profile WWW Email
« Reply #6 on: September 25, 2009, 08:58:53 »

Thanks everyone for your comments and for the confirmation that still in PureMVC you can skin a cat in many ways.
Logged
Pages: [1]
Print