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 inform a new mediator/view about the data to display  (Read 6590 times)
olist
Newbie
*
Posts: 7


View Profile Email
« 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
Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #1 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.
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
olist
Newbie
*
Posts: 7


View Profile Email
« Reply #2 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.
Logged
Pages: [1]
Print