PureMVC Architects Lounge

Announcements and General Discussion => Getting Started => Topic started by: olist on October 09, 2008, 06:38:30



Title: How to inform a new mediator/view about the data to display
Post by: olist on October 09, 2008, 06:38:30
Hi all,
I'm new to PureMVC, so I guess the answer to my problem may be quite obvious:

I work on a AS3 application, Flex is not envolved. I have a combo box containing an array of car objects, and the user can click a "View Details" button to open a layer with more information about the selected car.

The layer I open is a view component that I create as soon as the notification is received:

:
[ApplicationMediator.as]
override public function handleNotification(notification : INotification) : void {
switch(notification.getName()) {
case ApplicationFacade.VIEW_CAR_DETAILS:
// Get the object of interest from the notification
var car:Car = notification.getBody() as Car;

// Create the view component
var carDetailsLayer : CarDetailsLayer = new CarDetailsLayer();

// Register a new mediator for the component
facade.registerMediator(new CarDetailsLayerMediator(carDetailsLayer));

// Add the component to the display list
mainHost.setLayerContent(carDetailsLayer);
break;
}
}

Now I want to know which is the best way to inform the new Mediator/Component about the object of interest, the car. Since there is no such thing as a CarProxy that knows the current selection, I pass the selected car as the body of the notification. But the mediator itself can't listen to the notification since it doesn't exist yet when the notification is sent. And as Cliff writes in his Best Practice guide, mediators should only react on notifications instead of providing an own API.

I hope you can give me a hint what is the best practice for this case.
Thanks, Oliver


Title: Re: How to inform a new mediator/view about the data to display
Post by: Joel Hooks on October 09, 2008, 06:53:41
the constructor for CarDetailsMediator:

:
private var car:Car;

public function CarDetailsMediator(viewComponent:CarDetails, car:Car)
{
     this.car = car;
     super(NAME,viewComponent)
}

Then you can shove it into the view however you like.


Title: Re: How to inform a new mediator/view about the data to display
Post by: olist on October 09, 2008, 07:08:24
Thanks! That's pretty straight forward. Maybe I thought too much about asking Proxies, handling notifications and all that stuff.