PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: monkeyden on November 27, 2008, 07:08:18



Title: Getting my head around Commands
Post by: monkeyden on November 27, 2008, 07:08:18
Hi all,
Just getting started with PureMVC (and Flex really).  The docs don't seem to call it out directly, that I can tell, but it seems that Commands typically don't play a significant role in the execution of granular use case, for example:

"Commands may retrieve and interact with Proxies, send Notifications, execute other Commands, and are often used to orchestrate complex or system-wide activities such as application startup and shutdown."

I may be taking this too literally of course.  Correct me if I'm wrong but it appears that:

  • Mediators tag the viewComponent, or it's children, with event listeners
  • After user interaction, the Mediator's listener methods are fired
  • The Mediator interacts with the proxies to fulfill the use case.

Please correct me if my understanding is incorrect.

Thanks


Title: Re: Getting my head around Commands
Post by: Jason MacDonald on November 27, 2008, 07:30:21
Mediators can listen for events from components and then send notifications to commands to handle the interactions with the proxies, especially if any kind of application logic needs to be applied, then send the response back to the mediators to give to the view components. I try to keep most of my application logic in commands and keep mediators as "dumb" as possible. While some find it acceptable to have Mediators talk directly with Proxies, I personally like to keep all communication with proxies in my commands. Especially when setting and/or manipulating data.

There's no real right or wrong here, just a matter of preference.


Title: Re: Getting my head around Commands
Post by: monkeyden on November 27, 2008, 07:36:48
Thanks for responding Jason.  I guess I'm in the same camp.  One more question though.  Since Commands are stateless, would you simply load up the notification with the result of the Command execution, perhaps in the body?

Thanks


Title: Re: Getting my head around Commands
Post by: Jason MacDonald on November 27, 2008, 07:47:12
Thanks for responding Jason.  I guess I'm in the same camp.  One more question though.  Since Commands are stateless, would you simply load up the notification with the result of the Command execution, perhaps in the body?

Thanks

I have my command access the Proxy and have it get the info it needs, performing any necessary logic,  and then send a new notification with the response data as it's body (sometimes also a noteType if the mediator needs a discriminator) which a mediator is listening for. If the action I need the Proxy to perform requires an async call, then I have the Proxy send the notification when it's finished and have the mediator or command - a different command than the one who initiated the first request - respond to the Proxies completed or failed notification.


Title: Re: Getting my head around Commands
Post by: monkeyden on November 27, 2008, 07:59:45
Makes perfect sense. 

Thanks alot


Title: Re: Getting my head around Commands
Post by: Jason MacDonald on November 27, 2008, 09:40:38
Makes perfect sense. 

Thanks alot


Glad I could help.