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: Using the same proxy to handle different responses.  (Read 9177 times)
h34dch33z
Newbie
*
Posts: 3


View Profile Email
« on: December 31, 2009, 07:28:36 »

I am using PureMVC for the first time in addition to Flex for the first time. I've already spent about a month with Flex and decided to use PureMVC as I wanted a more AS3 based solution.
I was able to reuse my past Flex work without much trouble but I'll definitely want to refactor later on.
Things are going well so far.

The only issue I have so far is regarding Proxies.
I'm a Flash AS3 website kinda guy... this application stuff is new to me.

I have two functions I want to call from NotesProxy.as
I call notesProxy.loadNotes() which gives me all the note data as a fat XML... great. I call it from a mediator now but I will put it into a Command later on. That's what commands are for ;)
I also want to call notesProxy.saveNote(DTO). makes sense, right... call "Notes" related functions from the NoteProxy.

The issue is that my result handler expects a fat XML but the response from my saveNote() call may only return the added note or a success="true" confirmation. It may not return the full xml structure that getNotes() uses
(I call 2 different Delegates, one for each of the functions, from one Proxy. The delegates just point to different http locations... I'll clean that up later);

Maybe the idea of a "Proxy" is eluding me.

I'd appreciate your help in pointing me in the right direction.

source at www.wasimsingh.com/pmvcapp/PMVCTest.zip

So far, I've enjoyed working with PureMVC and have already realised some of its benefits... and it's only been 2 days!
I'm learning quickly. Hopefully I'll be able to contribute to the project in some way.
« Last Edit: December 31, 2009, 08:34:58 by h34dch33z » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: January 01, 2010, 08:03:11 »

Haven't looked at the source here but it sounds like you just need to get the process flow for async stuff worked out.

If you call saveNote on your proxy, it can't immediately return the actual data, that has to come asynchronously when it gets back from the server. But meanwhile the thread of execution continues in the client. The same code that made the call can't immediately consume the response. This means when your Proxy gets the data back it should send a note, that is listened for by a mediator or command who is interested in that result.

-=Cliff>
Logged
h34dch33z
Newbie
*
Posts: 3


View Profile Email
« Reply #2 on: January 05, 2010, 07:35:12 »

I understand that I have to wait for responses to come back in order to manipulate the response data. The Proxy implements IResponder and executes its result() function when the data gets loaded via a call to a delegate. The issue is that I only have one result function which handles one the return data. However, from the same Proxy, I make 2 calls ( loadNotes() and saveNote() ) that may return different data structures and I can't have multiple result() functions in my Proxy to handle differently structured response data.

As a temporary solution, I am assigning a dynamic variable to the async token before I send the request (as I'm using HTTPService to communicate). Then, when the result comes back I branch my logic based on that dynamic variable's value and send different notes accordingly. What I'm doing feels awfully hack-y though.
The good thing is that this proxy logic is insulated from the rest of the application due to the very nature of PureMVC.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: January 05, 2010, 01:38:59 »

I am assigning a dynamic variable to the async token before I send the request (as I'm using HTTPService to communicate). Then, when the result comes back I branch my logic based on that dynamic variable's value and send different notes accordingly. What I'm doing feels awfully hack-y though.
You're using the AsyncToken pattern precisely as it was intended. What feels hacky?

-=Cliff>
Logged
h34dch33z
Newbie
*
Posts: 3


View Profile Email
« Reply #4 on: January 05, 2010, 02:11:17 »

Assigning a dynamic variable that's then used to branch later on felt hacky.
I wasn't sure I was using it the right way. I am accustomed to creating and managing  URLRequest Loader objects, not using HTTPService so the ASyncToken is new to me.
My insecurity was based on my lack of knowledge.

Thanks, Cliff.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: January 08, 2010, 11:00:09 »

I hear you.

In fact the whole concept of dynamic variables feels totally hacky and non-OOPish to me as well, but such is the legacy of ActionScript and JavaScript.

However, I can say that after using it for several years, the AsyncToken pattern is really the one place it 'feels right' for me. You can ease the awkwardness a bit by making sure you only set and branch on constant values rather than literals.

-=Cliff>
Logged
Pages: [1]
Print