8

This question has been striking me for many days...

Let's say I have a very simple Backbone app with a list of items. When you click on an item, you see a detailed view of this item.

Is it better to

  • create just ONE DetailedView and reuse it when the user clicks on the different items ; OR
  • create one new DetailedView at each click ?

I prefer option 2, but there issues because I don't destroy the views properly, and get the infamous "ghost views" problem with events firing from nowhere !

What is the best practice ?

Blacksad
  • 14,906
  • 15
  • 70
  • 81
  • This is a very popular question, with quite some discussion and advice given here: http://stackoverflow.com/questions/7567404/backbone-js-repopulate-or-recreate-the-view and here: http://stackoverflow.com/questions/6859187/when-changing-the-model-for-a-view-is-it-better-to-replace-the-model-or-create – SunnyRed Jan 27 '12 at 19:21

1 Answers1

2

I re-use views in similar circumstances. Just reuse DetailedView. That way:

  • no need to create a structure to track all the views (since you wouldn't want to duplicate an already created view.)
  • No need to worry about memory size expanding without limit through long usage of the webapp
Larry K
  • 47,808
  • 15
  • 87
  • 140