PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: inchworm on January 30, 2010, 12:10:50



Title: What is considered the best practice for adding viewComponents to the stage?
Post by: inchworm on January 30, 2010, 12:10:50
First of all, thank you Cliff for all of your hard work on the framework and also your dedication to this forum. It's really great, as a self taught developer, to have places like this to go to which are active and responsive and help me along my way.

I have a rather simple application right now which displays a 3D timeline. The timeline has very little functionality and as such only needs one mediator. My current setup is an ApplicationMediator with a reference to the stage as its viewComponent, and a TimelineMediator with an instance of the 3D timeline as its viewComponent.

When I want to add the timeline to the stage/display list, I can think of two ways to do it. One way would be to send a notification with a reference to the timeline viewComponent as its body. Then the ApplicationMediator would handle that note and add it to stage. The other way is to have the ApplicatationMediator listen for a notification and then add the viewComponent through its mediator's reference in the facade.
:
addChild(facade.retrieveMediator(TimelineMediator.NAME).getViewComponent() as DisplayObject);
I've used both methods and they work well but I was wondering if there is an alternative best practice that maybe I don't know about? Is it ever wise to pass a stage reference to your Mediators and just forgo the ApplicationMediator/StageMediator all together?

Thanks!

- Rob


Title: Re: What is considered the best practice for adding viewComponents to the stage?
Post by: mariusht on January 30, 2010, 02:17:33
Go with:
...send a notification with a reference to the timeline viewComponent as its body. Then the ApplicationMediator would handle that note and add it to stage.

You don't want to make dependencies between mediators in you application.

Mariush T.
http://mariusht.com/blog/ (http://mariusht.com/blog/)


Title: Re: What is considered the best practice for adding viewComponents to the stage?
Post by: inchworm on January 31, 2010, 01:21:43
thanks mariush!


Title: Re: What is considered the best practice for adding viewComponents to the stage?
Post by: puremvc on January 31, 2010, 08:33:46
...send a notification with a reference to the timeline viewComponent as its body. Then the ApplicationMediator would handle that note and add it to stage.
This is the right approach. Don't pass around references to the stage, and try not to retrieve and manipulate mediators if you can avoid it.

-=Cliff>


Title: Re: What is considered the best practice for adding viewComponents to the stage?
Post by: inchworm on February 01, 2010, 02:39:23
Is it ok to retrieve mediators in my commands? Or should i be going about that differently as well?


Title: Re: What is considered the best practice for adding viewComponents to the stage?
Post by: mariusht on February 01, 2010, 07:42:45
Command may register, retrieve and remove another Proxy or Mediator

Look at my blog post http://mariusht.com/blog/2009/05/28/puremvc-actors-and-their-responsibilities/ (http://mariusht.com/blog/2009/05/28/puremvc-actors-and-their-responsibilities/)

Mariush T.
http://mariusht.com/blog/


Title: Re: What is considered the best practice for adding viewComponents to the stage?
Post by: puremvc on February 01, 2010, 08:28:19
Is it ok to retrieve mediators in my commands? Or should i be going about that differently as well?

The best practices document does mention that this is a practice to be avoided. Communicate with Mediators by sending them notifications if possible.

-=Cliff>