PureMVC Architects Lounge

Announcements and General Discussion => Getting Started => Topic started by: sinosoidal on October 15, 2008, 02:30:44



Title: Can i send notifications from mediators to proxies?
Post by: sinosoidal on October 15, 2008, 02:30:44
Hi,

Before I started doing anything in puremvc i read half of the documentation and try to put the example on the documentation working. I was a little bit disapointed with the example because it was not a complete sample.

In the example, the login command is declaraded on the application facade and then, onTryLogin a notification is sent for that.

However, in the diagram, its possible to comunicate directly between mediators and proxies and thats what i'm trying to do, but its not working.

This is what i'm doing in my mediator:

override public function listNotificationInterests():Array {
            return [AccessProxy.LOGIN,
                  AccessProxy.LOGIN_FAILED,
                  AccessProxy.LOGIN_SUCCESS];
      }
      
      override public function handleNotification(notification:INotification):void
      {
         switch(notification.getName()) {
            case AccessProxy.LOGIN:
               var loginProxy:AccessProxy = facade.retrieveProxy(AccessProxy.NAME) as AccessProxy;
               loginProxy.login(accessPanel.loginVO);
               mx.controls.Alert.show("notification sent");
               break;
         }
      }      
      
      private function onTryLogin(event:Event): void
      {                  
         sendNotification(AccessProxy.LOGIN,accessPanel.loginVO);   
      }

Can anyone clarify me this?

Thanks,

Nuno





Title: Re: Can i send notifications from mediators to proxies?
Post by: Joel Hooks on October 15, 2008, 08:45:25
No, proxies don't receive notifications. You are communicating directly with your proxy by grabbing its instance and calling methods on it. onTryLogin is sending a Notification which should be retrieved by a Command, which in turn will access the proxy in the same fashion. You could substitute this in the onTryLogin method:

:
               var loginProxy:AccessProxy = facade.retrieveProxy(AccessProxy.NAME) as AccessProxy;
               loginProxy.login(accessPanel.loginVO);

You have a circular reference going here, and AccessProxy.LOGIN is probably not needed at all. Instead you would just have:

:
      override public function handleNotification(notification:INotification):void
      {
         switch(notification.getName()) {
            case AccessProxy.LOGIN_SUCCESS:
               mx.controls.Alert.show("access granted");
               break;
            case AccessProxy.LOGIN_FAILED:
               mx.controls.Alert.show("access denied");
               break;
         }
      }