[Pkg-javascript-commits] [backbone] 01/28: Remove coupling from model to view in example app by listening to model's 'destroy' event to remove the view.
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 17:01:23 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.5.3
in repository backbone.
commit f77033d3c03eed9e356e0540c32a69c4a34f2af8
Author: James Coglan <jcoglan at gmail.com>
Date: Fri Jul 22 14:40:11 2011 +0100
Remove coupling from model to view in example app by listening to model's 'destroy' event to remove the view.
---
examples/todos/todos.js | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/examples/todos/todos.js b/examples/todos/todos.js
index 47c7e37..38f1f6e 100644
--- a/examples/todos/todos.js
+++ b/examples/todos/todos.js
@@ -28,12 +28,6 @@ $(function(){
// Toggle the `done` state of this todo item.
toggle: function() {
this.save({done: !this.get("done")});
- },
-
- // Remove this Todo from *localStorage* and delete its view.
- clear: function() {
- this.destroy();
- this.view.remove();
}
});
@@ -102,9 +96,9 @@ $(function(){
// a one-to-one correspondence between a **Todo** and a **TodoView** in this
// app, we set a direct reference on the model for convenience.
initialize: function() {
- _.bindAll(this, 'render', 'close');
+ _.bindAll(this, 'render', 'close', 'remove');
this.model.bind('change', this.render);
- this.model.view = this;
+ this.model.bind('destroy', this.remove);
},
// Re-render the contents of the todo item.
@@ -153,7 +147,7 @@ $(function(){
// Remove the item, destroy the model.
clear: function() {
- this.model.clear();
+ this.model.destroy();
}
});
@@ -234,7 +228,7 @@ $(function(){
// Clear all done todo items, destroying their models.
clearCompleted: function() {
- _.each(Todos.done(), function(todo){ todo.clear(); });
+ _.each(Todos.done(), function(todo){ todo.destroy(); });
return false;
},
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git
More information about the Pkg-javascript-commits
mailing list