PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: codecraig on September 24, 2008, 06:36:43

Title: Best way to take single view to multiple views
Post by: codecraig on September 24, 2008, 06:36:43
I currently have a rather complex UI.  In it there is a particular view which has its own Proxy, Mediator and view components, but now I need to allow the user to multiple displays of it.  So instead of a single view, maybe I use a tabbed style view.

For example, say this view displays stats about ONE baseball team.  It lists players, batting averages, win/loss, etc.  If they want to look at another team there is a combo box and they select a team and click "update" and the view updates.

Now, I need to have N-number of these views displayed for different teams.  So, if I did a tabbed view they could have 3 tabs (for example), each tab displays stats for a different team.

Is there a recommended approach to refactoring my code to support this?  Right now it's all based on getting data and displaying data for one team.  Now it seems like I need a parent proxy (which handles giving data about a team to the correct child proxy) and a parent mediator and a parent view.

What do you think?

Title: Re: Best way to take single view to multiple views
Post by: puremvc on September 24, 2008, 07:19:10
I don't know that I'd have a separate proxy for each team's stats. I'd expect one proxy that has an arraycollection of VO's of team stats. If there are three VO's of team stats then the ArrayCollection could be a data provider for a custom tab navigator component which could show a tab for each VO. Keep in mind that ArrayCollection can have a dynamic filter applied to it, changing the set of VOs in the list and thus the number of tabs displayed. Since ArrayCollections automatically inform the view components for which they are data providers, it leverages Flex's own data-aware view components. You may only need the custom tab navigator component and a mediator for it (and not one for each child if its display only).

Otherwise, you can do this the classical way of instantiating a mediator for each tab and ensuring it gets the data it needs for its view component.