Nested View Components in PureMVC

I have had quite a few queries regarding how to handle nested view components in PureMVC and have decided to whip up a very simple and quick example of how to handle this dilemma.

In fact its actually not a biggie really, the only real thought has to go into when and where you register the mediators. In my example I highlight two methods of how to tackle this aspect: + A nested view is already added to the display list and its mediator is registered in the StartupCommand. + A view component is dynamically created and added to the display list by a Mediator, this mediator also registers the new nested view components mediator.

1) The app consists of a main HolderView component with a button. Within this view component is the PanelView component registered on startup. When the main button is clicked the PanelView will pick up on the notification sent and display the notification body in a text field.

2) The PanelView also has a button and when this is clicked PanelView will load a new instance of the ButtonView. When ButtonView is clicked PanelView will pick up on the notification sent and display the notification body in a text field.

So you see nested view components are super super simple in PureMVC, have a play and come up with you own variations. Maybe have a command to handle all dynamically loaded view components? Please note this is a simple example!

View Source

Nested View Example

Comments