PureMVC Architects Lounge

Announcements and General Discussion => Getting Started => Topic started by: sinosoidal on November 19, 2008, 08:48:32



Title: Proxy notification for multiple mediators
Post by: sinosoidal on November 19, 2008, 08:48:32
Supose there are two mediators M1 and M2. There is also a proxy P that has a method list(path:String). This method will use a HTTPService to retrieve data. Once data is returned proxy P sends a notification. Both mediators M1 and M2 have interest on that notification.

Now, M1 retrieves the proxy P and calls list('fooo'). What is the best way to make sure M2 won't do a thing with the result notification?

Is it better to have a HTTPService for each mediator? Should both mediators check the notification body if they must ignore it?

Thanks


Title: Re: Proxy notification for multiple mediators
Post by: puremvc on November 19, 2008, 11:05:26
The best way is for M2 not to be interested in the same notification.

Otherwise, you can use the type property of the note as a discriminator. This is basically the Asynchronous Token pattern. When you make a request you need a way to know what to do when the data comes back.

Have Proxy P's list method take an extra string param called 'invoker'.

Have Mediator M1 pass its name (this.getName()) to the list as the invoker param.

When Proxy P makes the remote call on HttpService, an AsyncToken instance is returned. Rather than ignoring that return, get it into a var and store the invoker name on it:

:
var token:AsyncToken = service.send();
token.invoker = invoker;
Note that AsyncToken is a dynamic class you can add any property name to, so 'invoker' isn't magic.

When the result comes back, get not only the data from the ResultEvent but the token as well:

:
var token:AsyncToken=resultEvent.token;
That token has the invoker nam on it so when you send the notification:
:
sendNotification(MyProxy.RESULT,data,token.invoker);
In M1 and M2, check the note type:

:
if (note.getType() = this.getName())
{
   switch(note.getName())
   {
      case MyProxy.RESULT:
         Do stuff
         break;    
   }
}
Cheers,
-=Cliff>


Title: Re: Proxy notification for multiple mediators
Post by: itnilesh on February 07, 2012, 09:51:35
You have given simple situation where notification screen A sends notification and updates screen A only .
What in case where A updates another screen ????????????


Title: Re: Proxy notification for multiple mediators
Post by: puremvc on February 07, 2012, 11:10:07
If one view component needs to trigger a change in another view component that the first does not have a reference to and cannot send a bubbling event up the display list, then mediate. Both view components should have mediators. The first view component sends an event listened for by its mediator, that mediator sends a notification listened for by the second view component's mediator, who in turn sets some data or calls a method on the second view component.