 |
 |
|
|
|
How do I handle deferred instantiation of view components? |
|
Saturday, 16 August 2008 |
QUESTION: I am having some difficulties loading views components in a Flex ViewStack. See the steps:
- MainApp load - ViewStack default view: A - I login - ViewStack Changes view to: B - View B have more two components inside (B.1,B.2) - When i tried send data for components B.1 and B.2 their are unavaible it sends an error that object is null
I have done some research and find maybe it's creationPolicy, the default is "auto" and I changed it to "all" and the objects are now avaliable.
My question is how to handle this without the creationPolicy=all, because now my App just have 2 views and 3 components, but when I have 50 components this will take a long time to start will it not? What is the best practice to do this?
Answer: This is the cannonical deferred instantiation problem.
The simplest starup scenario for a Flex or AIR app is that the MXML application creates itself first (the view components), then the PureMVC appraratus we build attaches itself to the MXML app by registering Mediators that have references to the already constructed view components in its hierarchy. However a feature of Flex is deferred instantiation of view components. In a ViewStack, for instance, although several children may be defined in the MXML, only the first visible child will be instantiated by default (creationPolicy="auto"). The other children will be instantiated only when you navigate to them. This is nice because it helps startup go faster, and the user may not navigate to all the children, so time and memory is conserved. Unfortunately, now our simple scenario above is no longer enough, because at startup time, we don't have references to all the view components that will eventually need mediation. Although we could register the mediators and later give them references to the view components as they are created, that sort of defeats the point of deferred instantiation. So we need to defer the creation and registration of the Mediator as well.
One thing to note here: Deferred instantiation is great, but OPTIONAL. If the children of this ViewStack are pretty simple, as I imagine from your description they are, then instead of jumping through hoops trying to deal with it in the framework, simply set creationPolicy=all in your viewstack and be done with it.
Remember this is a simple case. Deferred instantiation is the default behavior because it is expected that you want the most optimal startup experience. And if you have a ViewStack with a ton of stuff in it that will take a long time to instantiate and so the perceived load time is longer. So...
Inevitably, you will have an app complex enough that you have to deal with this problem. Then you need to study the release notes and source code for the Slacker demo. |
|
|
PureMVC on the Web
|
João Pescada has produced a nice PureMVC / AS3 demo - a searchable image gallery. |
|
Jonathan Campos has put together a nice introductory PureMVC article with an example built around the Netflix API. • Netflix API with PureMVC - Article
|
The guys over at Pyjamas (a Python port of GWT) have made their compiler so efficient that it can take virtually any Python library and it will compile to Javascript. They loved the look of PureMVC Python, and decided to do a couple of demos that use it. • Pyjamas Project • EmployeeAdmin Demo: Original / Pyjamas • Pyjamas PureMVC Timesheet Demo |
|
Chandima Cumaranatunge, co-author of the O'Rielly book AS3 Design Patterns, and long-time PureMVC community member recently created a simple Flash/AS3 MultiCore demonstration application accompanied by an informative article that's an excellent introduction to the benefits of working with MultiCore. • Who Moved the Cheese? - Demo / Source / Article
• ActionScript 3 Design Patterns |
|
Ahmed Nuaman has published a well conceived and received AS3/PureMVC tutorial at FlashTuts.com. It's a good place for the learner to get their feet wet, and goes into the difference between using PureMVC with Flex as opposed to Flash or pure AS3. • Understanding the PureMVC Open Source Framework • FlashTuts Website • Ahmed's Website
|
|
Recent Project Activity
|
The PureMVC MultiCore framework for
Native JavaScript is now available. It has no dependency on other frameworks and provides its own optional namespace and class simulation. |
|
PureMVC Standard Version for Perl 1.0 has been released, complete with unit tests and online documentation. • PureMVC Standard Framework for Perl
|
|
Release 1.3 of the AIR DesktopCitizen Utility which allows applications to remember their window size, position and maximized/minimized state
each time it is launched. It also provides a facility for requiring
confirmation (or executing some shutdown process) before the application
window closes.
• AS3 / AIR Desktop Citizen Utility • CodePeek Demo |
|
The classic PureMVC EmployeeAdmin Demo has been ported to yet another language! Although PHP is usually thought of as a server language, using PHP-GTK, Sasa Tarbuk recreates th a desktop app. |
Version 1.0.8 of the PureMVC Java MultiCore port is now available. It supports JavaFX and handles threading properly.
|
|
|