PureMVC Architects Lounge

PureMVC Manifold => MultiCore Version => Topic started by: sysaux on April 03, 2009, 06:26:53



Title: Good logic for proxies
Post by: sysaux on April 03, 2009, 06:26:53
Hello!

I'm using multicore version of PureMVC and i implemented data modification logic by creating 4 proxies
for data object. For example, to work with "orders" i will write 4 proxy:
 - OrdersFetchProxy
 - OrdersInsertProxy
 - OrdersUpdateProxy
 - OrdersDeleteProxy

because if I implement all of this methods in single proxy class, I don't know
which operation(FETCH, UPDATE or DELETE?) returns OK or FAULT message.

How I may implement all data modification(and another - search, filter etc) operations in a single
proxy class, with different result messages? If proxy executes all income calls one after another,
I may remember current operation type in variable, and return result messages depend on this variable...

P.S.:Sorry for my bad English.


Title: Re: Good logic for proxies
Post by: puremvc on April 03, 2009, 10:09:08
Research the Flex API for the AsyncToken. Essentially when you make a service call you set any properties you want on the token that is immediately given back to you, it is a dynamic object supporting the addition of properties at runtime.

Use the AsyncToken object that is returned when you invoke a service call like this:

:
var token:AsyncToken =myHTTPService.send();
token.currentOperation=OrderProxy.DELETE;
token.orderID = currentOrder;

Later, when the result comes back:

:
var token:AsyncToken =resultEvent.token;

switch(token.currentOperation){

   case OrderProxy.DELETE:
   // delete token.orderID from order collection and send appropriate notification
   break;

   case OrderProxy.ADD:
   // add populated order with db generated id to order collection and send appropriate notification
   break;

   case OrderProxy.UPDATE:
   // replace modified order in order collection and send appropriate notification
   break;


-=Cliff>


Title: Re: Good logic for proxies
Post by: sysaux on April 04, 2009, 03:39:13
Thanks, Cliff. You have saved me from writing tonns of unneсessary code!