I'm on vacation for a few days, and Ava and Dale are taking a nap...so I went for a walk and thought up a component for playing around with in Swiz. Instead of using Swiz.executeServiceCall() to invoke methods on RemoteObjects, I cooked up a "RemoteMethodMediator." Its source code is attached.
I'll post a video about it next week, but the gist is that I love messaging, and I only want to work in events (vs. callback functions that usually just dispatch events). Instead of assigning result / fault callbacks, RemoteMethodMediator lets you tell Swiz "Hey, whenever you get a result from Service.doSomething(), dispatch the "SomethingController.GOT_SOMETHING" event and place "resultEvent.result" in "event.something." Then, any methods with GOT_SOMETHING mediated to them are called and simply passed the value.
Whew, yeah, that's going to need a video on Monday. For the curious, Here's the example of how it works when applied to the stock list example:
In Beans.mxml:
id="stockPriceService"
destination="ColdFusion"
source="ExampleService"
/>
<rpc:RemoteMethodMediator
remoteObject="{ stockPriceService }" methodName="getStockPrices"
resultProperty="stockPrices" resultEvent="{ StockController.STOCK_REQUEST_COMPLETE }"
faultEvent="{ StockController.SERVER_REQUEST_FAILED }"
/>
In StockController.as:
public function loadStockPrices() : void
{
Swiz.dispatch( StockController.STOCK_REQUEST_STARTED )
stockService.getStockPrices()
}
[Mediate( event="stockRequestComplete", properties="stockPrices" )]
public function stockPricesReceived( prices : Array ) : void
{
stockQuotes.source = prices
}
[Mediate( event="serverRequestFailed" )]
public function serverError() : void
{
Alert.show( "Oops! Server died!" );
}
Comment 1 written by Hmd on 2 November 2009, at 11:05 PM
First of all thank you for your post its really interesting, Actually i am working on something similar , but i didn't figure it out the best way to do it.
So i'am using webservices to communicate between flex and .net, but i am using something similar to your example to handle my services , but i'am afraid of having a kind of potential bug, which is related , at too many request for the same service at same time.
what i mean for example if i send request for how many Articles A i sold this three weeks and how many articles B i sold in one day and then i received the B answer before the A and its exactly the same service who is called . What is the right way to handle this cases of request...
Thank you