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!" );
}
