Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice with Backbone views: Reuse or create?

Tags:

backbone.js

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 ?

like image 289
Blacksad Avatar asked Jan 27 '12 19:01

Blacksad


1 Answers

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
like image 50
Larry K Avatar answered Oct 21 '22 17:10

Larry K