1

我正在使用 puremvc 框架来开发基于 flex 的项目。我的问题与延迟注册代理类和中介类的最佳方法有关?目前在启动命令上,我正在注册启动调解器。

我的代码有:

  1. ApplicationFacade.as
  2. 启动命令.as
  3. 启动调解器.as
  4. 登录命令.as
  5. 登录中介者.as
  6. 登录代理.as
  7. 登录视图.as

ApplicationFacade.as我正在向StartupCommand发送通知。StartupCommand注册StartupMediator

现在我的问题:

  1. 何时何地注册 LoginMediator
  2. 何时何地注册 LoginProxy
  3. 何时向 LoginCommand发送通知?
  4. 如果我们在LoginCommand中注册LoginMediatorLoginProxy就像

         公共类 LoginCommand 扩展 SimpleCommand
    实现 ICommand {
        覆盖公共函数执行(通知:INotification):无效
        {
            外观.registerProxy(新登录代理());
         门面.registerMediator(新的LoginMediator(app));
        } }

    现在,如果我 多次 发送LoginCommand通知,那么它会创建多个LoginProxyLoginMediator 实例。那么如何避免呢?

4

1 回答 1

1
  1. 在我的 startUpCommand 中,我注册了当前在舞台上拥有视图的所有调解员。我等待注册任何其他观点和调解人,直到需要它们。

  2. 我在我的 startUpCommand 中注册了几乎所有代理,因此它们可以从 flashVars 注册并从服务器加载数据。至于您的 LoginProxy,我会在您的 StartUpCommand 中创建它以帮助您入门。一旦您的应用程序增长,您可以将其移至设置登录中介的命令。

我建议将您的代码放在 switch 语句中,以确保您在正确的通知上执行代码并删除命令。

override public function execute(notification:INotification):void {
switch(notification.getName()) {
case AppFacade.START_UP:
// 删除启动命令
facade.removeCommand(notification.getName() );
休息;
}
}

您还可以在外观上使用 hasProxy 方法来确保您不会注册两个 LoginProxies。

if(facade.hasProxy(LoginProxy.NAME)) {
facade.registerProxy ...
}

于 2009-11-10T18:53:05.210 回答