PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: jaxim on April 09, 2010, 09:33:50



Title: Should a Command add an event listener?
Post by: jaxim on April 09, 2010, 09:33:50
I'm new to PureMVC, so i want to double check if what I am planning on doing is considered best practice or if there is a better way.

I have a Startup Command that registers a proxy. The proxy takes awhile to get its info, which is needed to start the application. In the meantime, nothing can be done until this info is returned, so there are no other proxies, mediators, etc. Currently, I have the startup Command add an event listener to the proxy and wait until the proxy indicates that the info has been returned. When the info is returned, then  the startup command registers the rest of the start up proxies and mediators that use this initial data.

The startup command is only called once.

Is this an okay practice? Is there a better way to go about this?


Title: Re: Should a Command add an event listener?
Post by: puremvc on April 11, 2010, 12:45:26
Not good, no.

You don't really want to kick Proxies into action when they're registered, otherwise you end up with these sort of issues.

You should register the Proxies, let them create their services or delegates, etc, but then await further instruction. This is the Model preparation phase.

Then register all your initial Mediators and let them set their view component listeners and fetch their proxy references. This is the View preparation phase.

You may choose to have your Mediators kick your Proxies into action at this time when they are registered, or you might have a Command that follows the View prep phase that goes and kicks off all the appropriate model calls to get data.

Now, when the calls come back from the Proxies, you already have the Mediators in place to listen for them and the view can organize itself accordingly.

Also if your startup is really complex with loading dependencies (i.e. can't load this till you've loaded that), you might look into either the Loadup utility or the StateMachine utility to help .

-=Cliff>


Title: Re: Should a Command add an event listener?
Post by: jaxim on April 12, 2010, 12:47:10
thanks. that helps a lot.