Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
public class RegisterMediatorForComponentCommand extends SimpleCommand implements ICommand{ public function RegisterMediatorForComponentCommand() { super(); } override public function execute(notification:INotification):void { var registerMediatorVO:RegisterMediatorVO = notification.getBody() as RegisterMediatorVO; if(registerMediatorVO) { var MediatorClass:Class = registerMediatorVO.MediatorClass; var viewComponent:UIComponent = registerMediatorVO.viewComponent; if(MediatorClass && viewComponent) { var mediatorName:String = MediatorClass.NAME as String; if(mediatorName && !facade.hasMediator(mediatorName)) { try { var mediator:IMediator = new MediatorClass(viewComponent) as IMediator; if(mediator) { facade.registerMediator(mediator); } } catch(e:ArgumentError) { trace("RegisterMediatorForComponentCommand Argument Error"); } } } } }}
public class RegisterMediatorVO{ public var MediatorClass:Class; public var viewComponent:UIComponent; public function RegisterMediatorVO(MediatorClass:Class, viewComponent:UIComponent) { this.MediatorClass = MediatorClass; this.viewComponent = viewComponent; }}
var registerMediatorVO:RegisterMediatorVO = new RegisterMediatorVO(LoginFormMediator, loginForm);sendNotification(AppNotifications.REGISTER_MEDIATOR_FOR_COMPONENT, registerMediatorVO);
facade.registerMediator(new IndexMediator(indexView);
Writing the entire app as one class might ultimately seem simple
var mediator:IMediator = new MediatorClass(viewComponent) as IMediator;if(mediator){ facade.registerMediator(mediator);}
facade.registerMediator(new LoginFormMediator(loginForm);
why not just skip that biz and register the mediator directly with the facade?
override public function execute(notification:INotification):void { var registerMediatorVO:RegisterMediatorVO = notification.getBody() as RegisterMediatorVO; for each (var proxyClass:Class in registerMediatorVO.proxies) { if (!facade.hasProxy(proxyClass.NAME)) { facade.registerProxy(new proxyClass()); } } ... continue registering mediator, etc.
Usually, a Proxy is pretty light and there usually aren't that many of them to register for a given app. I find that just registering them all to begin with (but not telling them to automatically fetch data) is a good way to ensure they're present and accounted for whenever needed. I don't see that delaying their instantiation until the mediator that needs them is registered has a lot of value. But if you have a situation where it does make sense, then the above seems like it would work to me.
why would you instantiate a Proxy before it's needed?
I have been trying to figure out a way to modularize the application into MultiCore without success...