Title: Mediators for views created at runtime Post by: mycroft on November 18, 2007, 11:36:32 Hi,
I'm new with PureMVC and this forum, and this might've been asked before. I have an app which creates the following hierarchy: App -> Component with SuperTabNavigator -> [dynamic tab including other custom components] The dynamic tabs could be a number of different views that are not related to each other and would need individual Mediators for each. My question is how do I initialize Mediators for those dynamic components? From what i've seen with PureMVC you have to pass an instance of the views to the view mediator to initialize it. How would I do that with dynamic added views to another component (SuperTabNavigator uses addChild to add a new tab). Your help would be greatly appreciated. Regards, Julian. Title: Re: Mediators for views created at runtime Post by: puremvc on November 19, 2007, 09:29:06 Hi Julian,
There are a number of ways of dealing with deferred instantiation in the View. Here are a few ways, and the pros and cons of each. 1) Creating Mediators ahead of time with dummy View Components, then later passing the real View Components to them in Notification bodies. Pros: 2) Defer instantiation of the Mediator until its View Component is created. (Recommended). The View Component who will have children dynamically created at runtime must arrange a way to alert its Mediator of child creation. This can be done with a custom event class that the Mediator listens for and which has a property that is a reference to the new child. Or you can send a regular event that alerts the Mediator that it should check a 'lastChildCreated' property that would hold a reference to this newly created child (hint:bind to the tab navigator's selectedItem property). When the Mediator hears this event, it gets the reference to the new child and based upon its id property or some other discriminator, determines the appropriate Mediator to instantiate and register. If the process of determining which Mediator to create is very involved, you might want to move this part of the process out to a Command, and have the Mediator respond to the event at the view simply sending a notification with the new View Component as the body and let the Command figure it out. Pros: 3) Turn off deferred instantiation for these children altogether. In the case of a normal ViewStack, TabNavigator or Accordion you can simply set creationPolicy="all'. This means that all the children will be created at startup, nothing will be deferred. (usually not recommended) Pros: Hope this helps, -=Cliff> Title: Re: Mediators for views created at runtime Post by: mycroft on November 19, 2007, 01:58:14 Thank you Cliff..That makes sense!
Title: Re: Mediators for views created at runtime Post by: shauno on November 20, 2007, 08:04:28 Purists will laugh at you and malign your ways. hahahah!! I think I shall dedicate a portion of each day to laughing at "purists"!! ;) Title: Re: Mediators for views created at runtime Post by: dbasch on May 18, 2008, 01:19:22 This is very good info regarding WHERE to instantiate dynamic proxies as well. I was confused about whether instantiating mediators within another mediator was proper. Thanks Cliff.
Derek Basch |