Question

When using Backbone.js and a template framework such as Underscore or Handlebars (Im using Handlebgars) when should a view have sub views?

For example I'm making a single page website that has like 5 different "pages" each page has different areas on it that show different data. A good example is the dashboard, it has about half a dozen widgets on it that show summaries of data. Each widget is unrelated to the others.

What I'm inclined to do is to make one view for each of the 5 pages and then to have those 5 views each load sub views into themselves.

This seems very logical to me but I cant seem to find any tutorials / documentation on it.

Is this a design pattern? Has anyone done this sort of thing?

Thanks.

Was it helpful?

Solution

I think it's a good idea to think in terms of seperation of concerns when it comes to views and subviews. In your example the dashboard contains 5 subviews. The dashboard shouldn't care how these subviews work and what they do. The subviews on the other hand shouldn't care about where they will be placed.

You'll make your live easier of you seperate your views this way, it's easier to maintain and it's also easier to swap views around in your application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top