Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone: is 100 + Views ok?

I have just started with backbone... I was excited about it until I ran into a something quite confusing. So with what I have seen while searching for backbone info is that a view is basically unique to one element.

Example project: Web page builder / editor

So reguarding the example project I am guessing that you will have a view Element() with methods that would do some of the following

  • Change CSS styles
  • Change text of element
  • Remove element
  • Add Class to element
  • Change by (id, class)

and in those methods they would do something like

this.el.style.color = 'red';

The only way I thought for this to be possible is to create a new Element({el: someElement}) for each element that is being changed.

So say you have 100+ elements on a page and 100+ views, that just wouldn't seem right to me.

If the questions confusing that's because I'm Confused so if you need any more info. comment...

Also I can't seem to work out where Models would come into a application like this because most of the info I have read about them is that they are used to contact the server, whereas in this case. that would only be when the page is saved.

So, is it Normal to have so many views?

like image 449
iConnor Avatar asked Oct 21 '22 04:10

iConnor


1 Answers

In my experience, the short answer is yes, that is fairly normal.

Generally in the sophisticated web applications in Backbone I have seen, it is certainly fairly common to have a few dozen views in the viewport. For example, a handful of views for the header, navigation, footer, and then maybe showing a dozen or so models, but each model is represented by a handful of views.

@mu's comment makes a good point that at some point maybe you need to just simplify your application's UI. But yes, if you are working on some sort of WYSIWYG style live web page editor, expect the order of magnitude of live view instances in the hundreds.

like image 127
Peter Lyons Avatar answered Oct 27 '22 09:10

Peter Lyons