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: One Mediator multiple Views?  (Read 5944 times)
Westside
Jr. Member
**
Posts: 12


View Profile Email
« on: December 03, 2008, 04:48:46 »

Hi,

Can someone provide a coding example of how I can have one mediator mediate two views?  So far I have this code (below) which works for one mediator and one view, but it seems like a lot of extra work to have one mediator for every view component so I would like my "mediator" to mediate for two views for example.

Here is my existing code:

public static const NAME:String = 'SearchMediator';

public function SearchMediator( viewComponent:Object )      {
     super( NAME, viewComponent );
     peopleSearch.addEventListener( PeopleSearch.LOAD_CATEGORY_TREE, doTreeLoad );
}
      
override public function getMediatorName():String   {
     return NAME;
}
      
protected function get peopleSearch():PeopleSearch      {
     return viewComponent as PeopleSearch;
}

private function doTreeLoad(event:Event):void {
     sendNotification( ApplicationFacade.LOAD_CATEGORY_TREE );
}

Any help highly appreciated.

-Westside
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: December 04, 2008, 11:55:31 »

You can drop the getMediatorName override. That's oldskool. Also move your adding of eventlisteners and any facade manipulation to onRegister, this keeps you from starting any conversations you can't participate in yet.

As for handling multiple view components that are children of the one passed in on the constructor, just add getters for them in the same way you add a getter for viewComponent, giving it a name and casting to the appropriate type. You can place listeners on the children directly, or put them on the view component and make the children send bubbling events.

-=Cliff>
Logged
Pages: [1]
Print