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]
Author Topic: Mediators and View Components: Am I doing this right?  (Read 7782 times)
Posts: 2

View Profile Email
« on: September 15, 2010, 10:48:56 »

What I'm doing NOW:

Often multiple instances of the view component would be used in multiple places in an application.  Each time I do this, I register the same mediator with a different name. 

When a notification is dispatched, I attach the name of the mediator to the body of the notification, like so:

var obj:Object = new Object();
obj.mediatorName = this.getMediatorName();
obj.someParameter = someParameter;

sendNotification ("someNotification", obj);

Then in the Command class, I parse the notification body and store the mediatorName in the proxy. 

var mediatorName:String = notification.getBody().mediatorName;
var params:String = notification.getBody().someParameter;

getProxy().someMethod(params, mediatorName);

On the return notification, the mediatorName is returned with it.

var obj:Object = new Object();
obj.mediatorName = mediatorName;
obj.someReturnedValue= someReturnedValue;

sendNotification ("someReturnedNotification", obj);

In the multiple mediators that might be watching for "someReturnedNotification," in the handleNotification(), it does an if statement, to see
if obj.mediatorName == this.getMediatorName returns true.  If so, process the info, if not, don't.

My Question is:
Is this the right way of using Multiton PureMVC?  My gut feeling is not.  I am sure there's a better way of architecting the application so that I don't have to test for the mediator's name to see if the component should be updated with the returned info.

Would someone please help and give me some direction as to what is a better way?

Global Moderator
Hero Member
Posts: 2871

View Profile WWW Email
« Reply #1 on: September 15, 2010, 04:14:52 »

Sure, this will totally work. I'm assuming that the Proxy sets the mediator name on the AsyncToken returned by its service call, and that's where it's getting the mediator name to send back out on its notification when the data comes back? If there aren't a huge number of mediators of that type registered, this sounds fine.

Pages: [1]