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);
......@@ -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