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: Proxy notification for multiple mediators  (Read 10504 times)
sinosoidal
Jr. Member
**
Posts: 15


View Profile Email
« 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
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 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>
« Last Edit: February 07, 2012, 08:47:00 by puremvc » Logged
itnilesh
Newbie
*
Posts: 6


View Profile Email
« Reply #2 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 ????????????
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 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.
Logged
Pages: [1]
Print