I am working with the Todos example application bundled with the latest version of Backbone (0.9.2) while learning about Backbone.js. My question is, why is the app designed to fire the render event twice when adding a model to the Todos collection?
If I place this line within the TodoView's render function:
// Re-render the titles of the todo item.
render: function() {
console.log("Rendering!");
this.$el.html(this.template(this.model.toJSON()));
Then "Rendering!" appears twice in the console. I understand this is because the view binds the model's change event to the view's render:
initialize: function() {
this.model.bind('change', this.render, this);
And render is called in addOne, which is bound to the Todos' add event:
addOne: function(todo) {
var view = new TodoView({model: todo});
this.$("#todo-list").append(view.render().el);
},
But is this double rendering design standard practice? It seems like the view should be rendered on creation (or entrance into the DOM), and then again if the underlying model changes. In this case, nothing is being changed, but render is being called twice.
Again, I am just learning Backbone, so I may have a basic misunderstanding that is leading to my confusion.