Commit 3c1f3855 authored by Kamil Ogórek's avatar Kamil Ogórek

Backbone list DOM element cached Fixes #682

parent 2191e029
...@@ -32,6 +32,7 @@ var app = app || {}; ...@@ -32,6 +32,7 @@ var app = app || {};
this.$input = this.$('#new-todo'); this.$input = this.$('#new-todo');
this.$footer = this.$('#footer'); this.$footer = this.$('#footer');
this.$main = this.$('#main'); this.$main = this.$('#main');
this.$list = $('#todo-list');
this.listenTo(app.todos, 'add', this.addOne); this.listenTo(app.todos, 'add', this.addOne);
this.listenTo(app.todos, 'reset', this.addAll); this.listenTo(app.todos, 'reset', this.addAll);
...@@ -39,7 +40,7 @@ var app = app || {}; ...@@ -39,7 +40,7 @@ var app = app || {};
this.listenTo(app.todos, 'filter', this.filterAll); this.listenTo(app.todos, 'filter', this.filterAll);
this.listenTo(app.todos, 'all', this.render); 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' // from being re-rendered for every model. Only renders when the 'reset'
// event is triggered at the end of the fetch. // event is triggered at the end of the fetch.
app.todos.fetch({reset: true}); app.todos.fetch({reset: true});
...@@ -76,12 +77,12 @@ var app = app || {}; ...@@ -76,12 +77,12 @@ var app = app || {};
// appending its element to the `<ul>`. // appending its element to the `<ul>`.
addOne: function (todo) { addOne: function (todo) {
var view = new app.TodoView({ model: 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. // Add all items in the **Todos** collection at once.
addAll: function () { addAll: function () {
this.$('#todo-list').html(''); this.$list.html('');
app.todos.each(this.addOne, this); 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