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: How to manage multi-view in one mediator?  (Read 5774 times)
yancaoshi
Newbie
*
Posts: 4


View Profile Email
« on: October 14, 2008, 09:20:18 »

Hi,

According to best pratice, a Mediator can be shared by several views. When initializing a mediator, we should pass that view component to constructor.
Now, I want to manage two relevant views in a mediator, one of which is to show the user list and the other of which is to edit the single entry. Since they are two different view components, how can I initialize the mediator?

public function Mediator( mediatorName:String=null, viewComponent:Object=null )

Thanks a lot.

yancaoshi
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #1 on: October 14, 2008, 10:40:22 »

The name of the mediator is all you need to be different.
:
facade.register(new Mediator('CustomName1', viewComponent);
facade.register(new Mediator('CustomName2', viewComponent);

A better way is to have your components return a unique name and use that in the constructor of the mediator.
:
public function Mediator(viewComponent:Object=null ) {
     super(viewComponent.getUniqueName(), viewComponent);
}
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: October 14, 2008, 06:44:58 »

A mediator has a viewComponent property that is an Object. That can be anything. So if you want one mediator to manage 2 view components the first idea is to mediate the container that contains both objects. If this is not possible or reasonable, then simply pass an array with the 2 view components as elements. Then make typed getters in the mediator that return element 0 or element 1 of the array cast to the appropriate type.

You can make the constuctor of this mediator take 2 typed arguments so that you are sure it is created with the right types. Then pass the array to super, as the view component argument. Of course this mediator like any other needs a name, so give it one that reflects that it mediates both components.

Since you used typed arguments for the constructor you can be sure the casts of the array elements to the proper types will not fail.

-=Cliff>
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #3 on: October 14, 2008, 07:29:11 »

Oops, looks like I misread the question. I thought you wanted new instances of one mediator to handle each component. My bad.
« Last Edit: October 14, 2008, 07:34:01 by jasonmac » Logged
Pages: [1]
Print