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: Best practice Mediator/Proxy  (Read 6328 times)
Qwaak
Newbie
*
Posts: 1


View Profile Email
« on: October 18, 2010, 08:27:20 »

Hi

I've just started to work with puremvc and a love it so far.
There are just some questions, where I'm not sure to get the things right done. One of it ist perhaps the same question, as crilbit wrote before me. I just want to get sure.

On Startup, I first register the proxies. Now I register a mediator, which handels the Navigation. Is it a good way, to call the loading/update-function in the proxy directly from the mediator?

For Exapmple:
:
public class NavigationViewMediator extends Mediator implements IMediator
{
public static const NAME:String                         = 'NavigationViewMediator'; 

private var _navigationView:NavigationView;
private var _familyProxy:FamilyProxy;


public function NavigationViewMediator(viewComponent:Object=null)
{
super(NAME, viewComponent);
}

override public function onRegister():void 

_familyProxy = facade.retrieveProxy( FamilyProxy.NAME ) as FamilyProxy;
_familyProxy.loadData();

_navigationView = new NavigationView;
viewComponent.addChild( _navigationView ); 
}

override public function listNotificationInterests():Array
{
return [
FamilyProxy.FAMILY_LOADED
];
}

override public function handleNotification(note:INotification):void
{
switch(note.getName())
{
case FamilyProxy.FAMILY_LOADED:
renderData();
break;
}
}

private function renderData():void
{
var data:FamilyVO;
for(var i:int = 0; i < _familyProxy.length; i++)
{
data = _familyProxy.getFamilyAt(i);
_navigationView.addNode(data.familyname, data.id);
}
}
}
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: October 20, 2010, 08:11:02 »

That's perfectly fine. We assume the View tier will have such a relationship with the Model tier, just not the other way around. The Model tier may be used in many apps so it must not 'know' anything about the View tier, but each app's View tier has but one goal: allowing the user to view and interact with the Model tier.

So we register the Proxies with the Model first, and then we register the Mediators who may safely assume when they are registered that the Proxies they need to form relationships with are already available.

-=Cliff>
Logged
Pages: [1]
Print