Wednesday, April 23, 2014

Too Many Views

It's tempting, given that Backbone affords developers such freedom in composing their applications, to create too many views. What might not seem like too many at first, probably is. There's simply no value in drilling down, ten levels, into the DOM hierarchy, and implementing a view at every stop. You're bordering on having a view for each DOM element, which is nonsense.

Let the template system do it's thing, and let the DOM events bubble up to your handlers. No need for views to be hyper-focused on one tiny section of the DOM. I get that it's good to have a strong division of responsibilities. It's also bad to have too many moving parts — no matter what you're building. This includes Backbone views.

So if you're keeping your single page application down to a sane handful of views, and things start to get complicated, stop. Don't make a diced-view soup. Take a walk, grab a coffee, and simplify your application. If your application has ten-thousand views — you're doing it wrong.