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: Getting my head around Commands  (Read 8219 times)
monkeyden
Newbie
*
Posts: 3


View Profile Email
« 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
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #1 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.
« Last Edit: November 27, 2008, 07:42:41 by jasonmac » Logged
monkeyden
Newbie
*
Posts: 3


View Profile Email
« Reply #2 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
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #3 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.
« Last Edit: November 27, 2008, 07:49:53 by jasonmac » Logged
monkeyden
Newbie
*
Posts: 3


View Profile Email
« Reply #4 on: November 27, 2008, 07:59:45 »

Makes perfect sense. 

Thanks alot
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #5 on: November 27, 2008, 09:40:38 »

Makes perfect sense. 

Thanks alot


Glad I could help.
Logged
Pages: [1]
Print