PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: JJfutbol on October 21, 2008, 12:40:02



Title: AsyncCommands - Proxy or Command handler parses/processes data?
Post by: JJfutbol on October 21, 2008, 12:40:02
In a current Flex/AIR project I figured I'd try a different approach within PureMVC than what I'm used too. I've created commands that make remote service calls and contain event handlers for fault or result events. If an asynchronous command receives a JSON result, should that handler have the responsibility of parsing the JSON and setting the necessary properties of your data objects or should that be the responsibility of the proxy?

I've always had all this functionality in my proxies but with this different approach I'm curious how others might be handling this. Do your commands know a lot about the model? Do they pull an object from an ArrayCollection, update the properties on that object? Or do you have your proxy parse the data returned (JSON, XML, etc.) to update the model?

Thoughts?


Title: Re: AsyncCommands - Proxy or Command handler parses/processes data?
Post by: Jason MacDonald on October 21, 2008, 01:14:39
Like you, I've always kept this stuff in my Proxies. If I were to use Commands as Responders then I would likely still keep the parsing in the proxies and just have the Command either create a proxy on result and set a property with the raw response, or have it access an existing Proxy and make a call like MyProxy.parseResult(myJSONResponse). I like the former since if the return is a Fault() then no proxy gets created since there's no data to feed it. This is very similar to how Cairngorm in Flex uses Commands as Responders by implementing an IResponder interface.

My $0.02.


Title: Re: AsyncCommands - Proxy or Command handler parses/processes data?
Post by: JJfutbol on October 21, 2008, 01:39:50
@jasonmac

Thanks for the reply! Appreciate your 2 cents although I feel its worth much more. :)

I've always had my service calls in my proxies but sometimes can get a bit out of hand. I noticed rarely ever having any commands and I liked the approach of having it in a command. I decided on this project to give it a shot.

With this though I realized my proxies don't really do much at all. From there I wondered if best to do parsing in the command but the parsing and setting properties or so coupled. I'll go with your suggestion. I figure the parsing is so data related that is the proxies responsibility so best to do that there.