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: question to deferred instantiation  (Read 3653 times)
marcink
Jr. Member
**
Posts: 13


View Profile Email
« on: February 27, 2009, 09:01:26 »

hi,

i would like to know if my approach to deferred instatiation goes along best practice:
here my mediator:
:
public class MyMediator extends Mediator
{
public static const NAME : String = "MyMediator";

public function MyMediator()
{
super(NAME);
}

override public function onRegister() : void
{
var vc : ViewComponent = new ViewComponent();
DisplayObject(vc).addEventListener(FlexEvent.CREATION_COMPLETE, this.addView);
this.sendNotification(AppFacade.ADD_CHILD_TO_STAGE, vc);
}

private function addView(e : FlexEvent) : void
{
this.viewComponent = e.target;
}
}

so basically, when i need a flex component, i register the mediator, and the mediator knows itself witch component to instantiate.

thanks
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #1 on: February 28, 2009, 06:44:07 »

Be careful when you need to send a notification in the onRegister method. The onRegister method only guarantee that this mediator has been registered. If you have registered it through a prepViewCommand with other mediators, the next mediators in the list will not be registered at this time. If the mediators that aren't registered at this time are interested in the notification you send, they will not receive it.

You better have to send the notification when the view is added to stage. But you have to be sure that all PureMVC instances interested by this notification are already registered.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: February 28, 2009, 07:39:14 »

Assuming the AppFacade has been registered, though, this should work fine. You could also have a command create the component, pass it to the constructor of MyMediator, register MyMediator and send the ADD_TO_STAGE note, but that just exposes one more actor to the view component, which we want to avoid. This way keeps MyMediator as the sole touchpoint for the view component in the PureMVC apparatus, which is what we're shooting for generally.

-=Cliff> 
Logged
marcink
Jr. Member
**
Posts: 13


View Profile Email
« Reply #3 on: February 28, 2009, 05:24:25 »

thanks a lot,
i'm always amazed, how fast i get the answers...  :D
Logged
Pages: [1]
Print