Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Welcome, Guest. Please login or register.
April 26, 2017, 04:24:19 PM
Home Help Search Login Register
News: ATTENTION: Spambots must die! Humans must visit http://contact.futurescale.com to request forum access.
Pages: [1]
Print
Author Topic: Proxy notification for multiple mediators  (Read 4269 times)
sinosoidal
Jr. Member
**
Posts: 15


View Profile Email
« on: November 19, 2008, 08:48:32 AM »

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: 2865



View Profile WWW
« Reply #1 on: November 19, 2008, 11:05:26 AM »

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:

Code:
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:

Code:
var token:AsyncToken=resultEvent.token;
That token has the invoker nam on it so when you send the notification:
Code:
sendNotification(MyProxy.RESULT,data,token.invoker);

In M1 and M2, check the note type:

Code:
if (note.getType() = this.getName())
{
   switch(note.getName())
   {
      case MyProxy.RESULT:
         Do stuff
         break;    
   }
}
Cheers,
-=Cliff>
« Last Edit: February 07, 2012, 08:47:00 AM by puremvc » Logged
itnilesh
Newbie
*
Posts: 6


View Profile Email
« Reply #2 on: February 07, 2012, 09:51:35 AM »

You have given simple situation where notification screen A sends notification and updates screen A only .
What in case where A updates another screen HuhHuhHuhHuh
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2865



View Profile WWW
« Reply #3 on: February 07, 2012, 11:10:07 AM »

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
Jump to: