Responsible Rendering
"Granular rendering makes responding to changes easier over time"
Views can be very cheap to make
Single Responsibility Principle
OOP principles (Gang of Four book mentioned)
Uncle Bob mentioned
"If you have a given method on a class it should only be responsible for one thing"
Interface Segregation
The interface should be split up and kept separate based on groups of responsibility
Do NOT do this:
render: function() {
this.renderComments();
this.renderContent();
this.renderEditor();
}
Organising applications around a view
It gives many benefits. A root element that holds the whole app (can be the
body
tag)Example:
var Comments = Backbone.View.extend({
el: $('.comments'),
initialize: function () {
this.collection = new CommentsCollection();
this.listenTo(this.collection, 'add', this.renderComment);
this.listenTo(this.collection, 'add remove', this.renderCommentCount);
this.collection.fetch();
renderComment: function(model){...},
renderCommentCount: function(model){...},
events: {
'submit form': 'createComment',
...
}
}
})
He argues that it's very convenient to have one centralised view that kicks of everything and organise you app around a singleton object.You get many benefits, life cycle events, references, events.