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: Should a Command add an event listener?  (Read 6224 times)
jaxim
Full Member
***
Posts: 22


View Profile Email
« 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?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 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>
Logged
jaxim
Full Member
***
Posts: 22


View Profile Email
« Reply #2 on: April 12, 2010, 12:47:10 »

thanks. that helps a lot.
Logged
Pages: [1]
Print