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: Proxy Calling Proxy  (Read 11068 times)
cturner
Newbie
*
Posts: 2


View Profile Email
« on: October 01, 2008, 03:12:29 »

I wanted to know if it is good practice to have one proxy use the retrieveProxy function and call a method on another proxy?  I realize I could also call a command that would make the function call on the 2nd proxy.  I am in favor of the command approach b/c then the proxies are not tied together. 

Thanks.
Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #1 on: October 01, 2008, 06:53:02 »

Cliff will usually tell people to use the path with less code, unless you need to make the call in other places also. There is nothing wrong with proxies calling other proxies. I find it absolutely essential myself.

The restriction is that you don't want you flex view components calling your proxies. I break this rul in one place, with the AppSkeleton's ConfigProxy and LocaleProxy because it makes for really clean localization and injection of variables from my config.xml.

Cheers.
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
minhv
Newbie
*
Posts: 4


View Profile Email
« Reply #2 on: October 24, 2008, 02:17:09 »

I've a similar question regarding proxy communication to proxy.  I did some searches on this issue on this forum but still can't arrive at a clear conclusion. 

Here's the problem that I've and seen in many posts.  I have a proxy(AggregateProxy) that uses data from many other proxies. So I'm using facade.retrieveProxy to access other proxy in the AggregateProxy.  The AggregateProxy has the responsibility of sorting the collection of data, and some other minor tasks.  The problem that I'm running into is when a search/filter interaction occur, all proxy except AggregateProxy needs to fetch a new set of data with the search/filter condition.  Once the data is fetched(Async) the AggregateProxy needs to know so it can update the master collection and tell the view to update.

I had thought about several solutions but I think there's a better way to go about it.
 
#1.  Handling this with multiple notifications.  On search/filter interaction the view mediator would call the filter/search method on AggregateProxy, which then calls each proxy filter/search method.  The view mediator also listens to all proxy filter/search complete notification. On filter/search complete notification view mediator call AggregateProxy#update() method which updates the master collection data.  Then the AggregateProxy send notification of changes to the collection which mediator pickup and update the view. With this method I feel like the single view mediator has too many responsibilities.  After all the view mediator is really only interested in the master collection data change notification.

#2.  Similar to #1 but using command.  Register a command for search/filter notification in ApplicatinFacade(is there a better place?).  This command would call filter/search method on each proxy in existence and dynamically register command for the search/filter complete notification. The search/filter complete commands call the AggregateProxy#update() method.   Then the AggregateProxy send notification of changes to the collection which mediator pickup and update the view.   

#3.  Create a mediator with null view.  This mediator would handle all notification from the proxy on search/filter complete then have AggregateProxy update it's master collection.  Here I'm pushing all the search/filter complete notification to a new mediator, which make it seems a bit cleaner but Cliff mentioned this is a bad idea since mediator does not go away. 

Are there better solutions to the situation of a proxy that compose of multiple proxy?
                                                                                         
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: October 27, 2008, 05:33:24 »

Given your setup, number two is the one that makes the most sense.

-=Cliff>
Logged
JJfutbol
Sr. Member
****
Posts: 53


View Profile WWW Email
« Reply #4 on: November 10, 2008, 11:19:31 »

@minhv

Did you end going with the second option? I wanted to ask about it if you did to see if you could share a bit more about how you went along with it. Why would you need to dynamically register a command for handling each result? I'm kind of in a similar situation in the sense that each call can go on its own but I need to handle when they are all completed. Curious how you are handling this.

I'm thinking about on each of my proxies having a simple "dataLoaded" boolean (read-only) that the proxy sets when data has been retrieved. Luckily for me the data is read-only and only needs to be loaded once. So I'm thinking about registering a CheckInitialDataDependenciesCommand that would retrieve each of the proxies every time one of the service calls completes. This way in that one command when all have finally completed it will do the next step, in this case firing off another command.
Logged
PieterGrobler
Newbie
*
Posts: 8


View Profile Email
« Reply #5 on: November 11, 2008, 06:26:29 »

I have come up with a solution that allows proxies notifying each other. I posted an example on http://blog.pietergrobler.com/node/3. Basically, proxies subscribe to another via a service. It would be interesting to get feedback on whether this is good practice or not.

I will also be posting more on proxies whose service can be reserved. This enables large data sets to be sent to garbage collection when the proxy has no active reservation.
Logged
Pages: [1]
Print