PureMVC Architects Lounge

Announcements and General Discussion => Getting Started => Topic started by: Peter on October 27, 2007, 01:22:28



Title: Using a generic Proxy to load data
Post by: Peter 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?


Title: Re: Using a generic Proxy to load data
Post by: Peter 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?


Title: Re: Using a generic Proxy to load data
Post by: puremvc 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>