What should be the top level of the Backbone.js application? View, shared object ,?

I am confused by what code I should create directly in Backbone.js. Should I create a generic App object that instantiates my views? Should I create an instance of App View that creates all the other views on the page and coordinates everything? Should I create views, models and collections and attach them to the window ?

Also, are controllers necessary? So far I have not found any use for them, and they are absent in many examples. Should I create an instance of the controller and create it for other objects, as is done in the framework of MVC of other languages?

My guess: I am free to do what I want, but I would prefer advice from someone who has used it quite a lot.

+6
source share
2 answers

Controllers are useful for managing the hashbang url.

If you do not have several pages, states that you want to save or want to use the buttons back and forth, then the controllers do not use.

Most of the examples I've seen have an AppView class that manages views and collections.

See Annotated Example

+4
source

Generally speaking, a router or controller will be the central element of your application, although it may be your own manual init or global object. Backbone provides you with utilities; it does not provide a complete nut-setting soup.

0
source

Source: https://habr.com/ru/post/888310/


All Articles