Commit 57c83b0d authored by Aaron Boushley's avatar Aaron Boushley

Remove tight coupling of the model to the view.

parent 0774dd53
...@@ -19,10 +19,9 @@ define(['underscore', 'backbone'], function(_, Backbone) { ...@@ -19,10 +19,9 @@ define(['underscore', 'backbone'], function(_, Backbone) {
this.save({done: !this.get("done")}); this.save({done: !this.get("done")});
}, },
// Remove this Todo from *localStorage* and delete its view. // Remove this Todo from *localStorage*.
clear: function() { clear: function() {
this.destroy(); this.destroy();
this.view.remove();
} }
}); });
......
...@@ -24,9 +24,9 @@ define([ ...@@ -24,9 +24,9 @@ define([
// a one-to-one correspondence between a **Todo** and a **TodoView** in this // a one-to-one correspondence between a **Todo** and a **TodoView** in this
// app, we set a direct reference on the model for convenience. // app, we set a direct reference on the model for convenience.
initialize: function() { initialize: function() {
_.bindAll(this, 'render', 'close'); _.bindAll(this, 'render', 'close', 'remove');
this.model.bind('change', this.render); this.model.bind('change', this.render);
this.model.view = this; this.model.bind('destroy', this.remove);
}, },
// Re-render the contents of the todo item. // Re-render the contents of the todo item.
...@@ -68,11 +68,6 @@ define([ ...@@ -68,11 +68,6 @@ define([
if (e.keyCode == 13) this.close(); if (e.keyCode == 13) this.close();
}, },
// Remove this view from the DOM.
remove: function() {
$(this.el).remove();
},
// Remove the item, destroy the model. // Remove the item, destroy the model.
clear: function() { clear: function() {
this.model.clear(); this.model.clear();
......
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