PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: mono2k on February 12, 2008, 07:23:42

Title: reusable components
Post by: mono2k on February 12, 2008, 07:23:42

Can someone guide me on developing reusable view components with puremvc/flex?

My app has two views - welcome screen and failed login screen (WelcomeVew, FailedLoginView), both have the same SignupBoxView MXML component.
SignupBoxView has a corresponding SignupBoxMediator. I'm using ViewStack to manage views:



<mx:ViewStack id="topStack" width="100%" height="100%">

<view:WelcomeView id="welcomeView" />
<view:FailedLoginView id="failedLoginView" />



I'm trying to register mediators in ApplicationMediator's constructor

public function ApplicationMediator(viewComponent:Object)

// welcome view
facade.registerMediator(new WelcomeMediator(app.welcomeView));

                        // welcome's signup box
                        facade.registerMediator(new SignupBoxMediator(app.welcomeView.signupBox));

// failed login view
facade.registerMediator(new FailedLoginMediator(app.failedLoginView));

                        // failed login's signup box
                        facade.registerMediator(new SignupBoxMediator(app.failedLoginView.signupBox));

appProxy = ApplicationProxy(facade.retrieveProxy(ApplicationProxy.NAME));

unfortunately, this not works for me, since app.failedLoginView is not a selectedChild of my ViewStack at the time of a facade startup and thus app.failedLoginView.signupBox is null.

Am I doing something completely wrong?

Title: Re: reusable components
Post by: puremvc on February 12, 2008, 09:02:05
This is a deferred instantiation issue. Here's a post where I've explained how to handle this: http://forums.puremvc.org/index.php?topic=70.msg247#msg247

Believe me, all this will be turned into a FAQ soon, I promise :)

Title: Re: reusable components
Post by: mono2k on February 12, 2008, 09:44:37
Hi Cliff! Thanks for an answer!

however, from adobe's documentation:

Navigator containers such as Accordion, TabNavigator, and ViewStack implement the ContainerCreationPolicy.AUTO policy by creating all their children immediately, but wait to create the deeper descendants of a child until it becomes the selected child of the navigator container

i.e. there is no point in listening a child's creationComplete event, rather we need to listen a child's child, this may be a code bloat... Could ViewStack's "change" event help?

Title: Re: reusable components
Post by: puremvc on February 12, 2008, 10:31:30
It all depends on the granularity of your view component / mediator.

And it doesn't matter what the depth of your child nesting is, the event will bubble. You just need to look at the UI component that was created and see what mediator register for it.