1
votes

If a have a collection with 50 models, it seems that I have 2 main options to render a list displaying 50 models:

- Option1 : Create a specific "item view" for each model and append these views to a main "list view". This will provide a direct relationship between each "item view" and each model, will be practical and inline with Backbone philosophy

- Option2 : Have only one "list view" rendering the list with "data-attributes" helping to fetch the corresponding model when an event happens on a given list item.

I understand that option 1 leverages Backbone in a much better way however I am concerned with the number of event listeners with this option. If I have 4 events that I have to listen to per item, this will mean that I will have 4x50=200 events listeners on my list... vs. 4 (delegated) events listeners with option 2.

Given that I want to use Backbone for a cordova application, which option would be the most appropriate ?

1
Run some tests and benchmark it.Michael.Lumley

1 Answers

0
votes

Maybe in that case it would be practical to used a "mixed" approach. A View for every model, but event listeners only on the top list view which will then delegate them further. This reduces event listeners on DOM elements.

Despite that - I would only use per-item-views when you need that extra functionality such as rendering and handling an edit form, or when single items are likely to be changed so that they need to re-render often. If that isn't the case use a single list view and let it handle the events.