Commit 958622a9 authored by Sindre Sorhus's avatar Sindre Sorhus

Merge pull request #756 from kamilogorek/backbone-elements-caching

Backbone list DOM element cached Fixes #682
parents cadd3294 3c1f3855
......@@ -32,6 +32,7 @@ var app = app || {};
this.$input = this.$('#new-todo');
this.$footer = this.$('#footer');
this.$main = this.$('#main');
this.$list = $('#todo-list');
this.listenTo(app.todos, 'add', this.addOne);
this.listenTo(app.todos, 'reset', this.addAll);
......@@ -39,7 +40,7 @@ var app = app || {};
this.listenTo(app.todos, 'filter', this.filterAll);
this.listenTo(app.todos, 'all', this.render);
// Suppresses 'add' events with {reset: true} and prevents the app view
// Suppresses 'add' events with {reset: true} and prevents the app view
// from being re-rendered for every model. Only renders when the 'reset'
// event is triggered at the end of the fetch.
app.todos.fetch({reset: true});
......@@ -76,12 +77,12 @@ var app = app || {};
// appending its element to the `<ul>`.
addOne: function (todo) {
var view = new app.TodoView({ model: todo });
$('#todo-list').append(view.render().el);
this.$list.append(view.render().el);
},
// Add all items in the **Todos** collection at once.
addAll: function () {
this.$('#todo-list').html('');
this.$list.html('');
app.todos.each(this.addOne, this);
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment