BackboneJS website structure

Ok, I'm trying to figure out all of this backboneJS . I understand that you must divide your site into modules and break each module into Models, Collections and Views, as described in this example .

Currently, the structure of my JS file looks like this:

-js -application.js -lib -jquery.min.js -backbone.min.js -underscore.min.js -modules -newsfeed.js //activity feed -file.js // page to upload files to -members.js // page that show other members of group //-general-site-logic.js?? 

I have two questions:

  • Should all logic be controlled from backboneJS ? If not, then where is this separate logic located in my application structure? Of course, the spine cannot control all your actions on the client side. What about activity that does not contain any collections?

  • Should I use RequireJS to manage modules when using BackboneJS or not? I found this example , but it seems to complicate the already confusing Backbone concepts even more.

I'm going to start a very heavy javascript application and really want to get this right before my code starts mushrooming!

+6
source share
2 answers

The great thing about Backbone is that it is just a collection of useful items that you can put together as you like. You can arrange it as you wish.

Of course, the highway cannot control all your actions on the client side.

Why not? I have a rather large client-side application where all the code (except for jQuery plugins, etc.) is written using Backbone constructs (Views, Models, Collections, Routers).

In our case, we use Rails, so we do not need to worry about the need to use other JS files. We split the project into many js (coffee) files, and the "asset pipeline" combines all this into one js file for us. (we need to inform the conveyor about some ordering rules, however ... models in front of collections, collections before viewing, etc.)

When we do this, we have the following setting:

 -assets -javascripts -backbone -collections -helpers -models -routers -templates -views -bootstrapper.js 

Of course, this is how we do it. For large projects, I always know where to find my components, and we create subfolders inside our different subtasks. For instance:

 -views -people -people_list.js -people_item.js -orders -order_list.js -order_item.js -order_form.js 

In small projects, however, you can put everything in one JS file, and this will not be a problem. Most examples of toys are laid out in this way.

An intermediate layout may be something where you simply separate your models from your views as follows:

 -models.js // models and collections -routers.js -views.js 

I suggest that you should get from this: "Organize, no matter how you want." Do what makes sense for the size of the project and how your organization understands your organization.

Backbone provides structure. However, it is not appropriate how this structure is designed.

+8
source

If this helps, I have bootstrap , the project starter integrates the trunk . js, coffeescript, sinatra, jasmine and skeleton .

This will allow you to start with the project structure and save time on integrating the technical stack. Also uses css skeleton for responsive design.

0
source

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


All Articles