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 a generic Proxy to load data  (Read 10471 times)
Peter
Full Member
***
Posts: 26


View Profile Email
« on: October 27, 2007, 01:22:28 »

Currently I could use a generic Proxy to load all xml data. In the body of the notification I can simply use a string to add to a query. The Proxy loads the data and informs a Mediator that the data is loaded, passing the data in the body of the notification.
But with several Mediators in the system all listening for DATA_LOADED this poses a problem.
I guess this could be solved in several ways but what would be considered good practice?
Logged
Peter
Full Member
***
Posts: 26


View Profile Email
« Reply #1 on: October 28, 2007, 06:44:34 »

If I use a node in the xml data to distinguish which content gets loaded and then use the type parameter of the notification, the Mediator can decide if it needs to do something.

in the Remote Proxy
if (a node in the xml == "homepage") {
facade.registerProxy(new ViewItemProxy("ViewItemProxy", data.xml));
sendNotification( ApplicationFacade.DATA_LOADED, null, "home" );
}

in the Mediator's handleNotification()

case ApplicationFacade.DATA_LOADED:
if(notification.getType() == "home"){
var proxy:ViewItemProxy = ViewItemProxy(facade.retrieveProxy("ViewItemProxy"));
var home:Home = new Home(); // a view object
home.main(proxy);
}
break;

Works, but is it a recommended solution?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: October 28, 2007, 08:45:03 »

Peter,

You're absolutely correct here, except that "home" should be a constant defined somewhere. But otherwise, you've got the gist of it.

The type parameter is to allow an instance that has been notified about something to determine if it really needs to take action. This can help reduce the overall number of notification names in the system.

I realize there is no guidance on this matter yet, but I'm actually building it into the FlashLite game that I'm writing as a demo for the AS2 port. And of course, I'll be updating the Best Practices doc with it soon, as well. Thanks for bringing it up here with a nice code example that I can point people to until I can get the docs updated :)

-=Cliff>

-=Cliff>
Logged
Pages: [1]
Print