PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: Westside on December 03, 2008, 04:48:46



Title: One Mediator multiple Views?
Post by: Westside 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


Title: Re: One Mediator multiple Views?
Post by: puremvc 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>