I have heard this asked a lot of times and as a foreword I would like to say that this is my opinion and I am not the best at debating points to the finest detail, this is just how I interpret the whole command issue. Also you have way way more experience with many different frameworks compared to myself so logic may differ?
I think the beauty of PureMVC is the way you can essentially utilise it to 'what suits you' to a degree
, over time I have pushed out a lot of PureMVC projects and still adapt and change certain styles and techniques with certain logic, this I don't think is necessarily a negative and see most changes I make a positive progression.
In the beginning I took much the same principle as you mention below, using commands to essentially prep the model and view, check for mediator registration etc. I am an advocate for referencing Proxies in the Mediators if
it is to simply get
some data, a reach in and grab situation.
Then Stef (www.flashcomguru.com
) and I had some chats about this whole scenario and each time we spoke I found I was tending to handle more aspects within a Command and was removing certain logic from the Mediators and Proxies. This then started solving a few issues I was having, primarily bloated Mediators and referencing the odd proxy within another proxy
With my latest application it is one of the biggest I have built so far and I will use some of this project as examples into my logic. There are lots of collation of data from the UI and processing of data received from remoting calls.
Mediators I try to keep them simple, grab data from the views, dispatch it and stuff it right back in again, I also handle form/view resets, determine whether certain components within the view are selected/enabled and dispatch notifications to change view state etc.
Due to numerous Proxies for various remoting calls, I am receiving back data which needs to be amalgamated, filtered and ultimately stored. This is where I have now really shifted logic to Commands. Heres a really rough example.
A booking engine has been sent a request for journeys and fares to populate a grid dependent on user defined journey times. I would have 2 proxies.
-The first has all the fares applicable to the search request times, each fare has a code used as a reference to retrieve further current info on that specific fare.
-The second proxy loads the current fare information and using getter methods passes back the extra fare information dependent on the fare code.
So I now need to filter these fares on certain current fare data and instead of having all this logic in one proxy (don't forget its using logic from 2 proxies) I use a Command. The first proxy receives the fares, sends a notification, a filter command which references both Proxies then filters all the fares and returns the new array collection into the first proxy for storage.
Here's another example. I have various TitleWindow popups which are presented in different formats i.e. Image/Text, Forms etc. I have a PopManager utility which accepts the popup params including a reference to the Facade. Anywhere in the application I can now call and open a popup i.e.
sendNotification( ApplicationFacade.HANDLE_POP, pObj, ResourceConstants.OPEN_POP );
and a HandlePopCommand will handle the logic of opening the correct style popup window (also closing it). To do that I simply use switch statements on the body and type of the notification and the command then checks to see if the pops mediator is registered and then opens (creates) or closes the popup accordingly.
Here's one more example. I have multiple view components which need to have all their data collated into one value object and then sent to a proxy for a remote request. A command has references to the specific mediators and calls the mediators getter method bringing in all the view data, populating the value object and filtering the data according to the data it is receiving. This prevents the Model receiving the data via multiple notifications and ensure an order to how the value object is populated.
On a final note, I do have a lot of commands on the slimmer bordering anorexic side which simply call different methods in a proxy dependent on the notification type i.e. if note.type() == reset a password, or reset a username etc. I then go though the various proxy method calling from there, this could
be done in the Proxy, but I am now more comfortable with the Commands handling this logic and cutting back on the proxy code. Following the theme of logins, there maybe different proxies handling different accounts so one command to handle this logic and call the appropriate proxy is ideal for me.
Ok, that's my thoughts on this, hope that helps in some way?
[ Website ] www.newtriks.com
[ Blog ] www.nutrixinteractive.com/blog/