From b28bb50520c54daec5d1fde1b807a50917ea29bf Mon Sep 17 00:00:00 2001 From: Loren Sands-Ramshaw Date: Sat, 4 Jun 2011 19:42:16 -0400 Subject: [PATCH 1/3] clarified example; fixed typo --- index.html | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 00eaafef..b879589c 100644 --- a/index.html +++ b/index.html @@ -1142,15 +1142,25 @@ var alphabetical = Books.sortBy(function(book) {

-var ships = new Backbone.Collection;
+var Ship = Backbone.Model.extend({
+  defaults: {
+    "name":  "Black Pearl"
+  }
+});
 
-ships.bind("add", function(ship) {
+var Fleet = Backbone.Collection.extend({
+  model: Ship
+});
+
+var pirates = new Fleet();
+
+pirates.bind("add", function(ship) {
   alert("Ahoy " + ship.get("name") + "!");
 });
 
-ships.add([
+pirates.add([
   {name: "Flying Dutchman"},
-  {name: "Black Pearl"}
+  {captain: "Jack Sparrow"}
 ]);
 
@@ -1585,7 +1595,7 @@ $(function(){

Backbone.sync

- Backbone.sync is the function the Backbone calls every time it + Backbone.sync is the function that Backbone calls every time it attempts to read or save a model to the server. By default, it uses (jQuery/Zepto).ajax to make a RESTful JSON request. You can override it in order to use a different persistence strategy, such as WebSockets, From 245acb08213c5cbdac8c6f860cdf6883c9720fc8 Mon Sep 17 00:00:00 2001 From: Loren Sands-Ramshaw Date: Sat, 18 Jun 2011 17:07:37 -0400 Subject: [PATCH 2/3] removed unused var --- examples/todos/todos.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/todos/todos.js b/examples/todos/todos.js index 1c7c8486..47c7e37f 100644 --- a/examples/todos/todos.js +++ b/examples/todos/todos.js @@ -196,7 +196,6 @@ $(function(){ // Re-rendering the App just means refreshing the statistics -- the rest // of the app doesn't change. render: function() { - var done = Todos.done().length; this.$('#todo-stats').html(this.statsTemplate({ total: Todos.length, done: Todos.done().length, From 2ed2af6698a23a36eb0de976ab840c97e39c9772 Mon Sep 17 00:00:00 2001 From: Loren Sands-Ramshaw Date: Sat, 18 Jun 2011 17:20:27 -0400 Subject: [PATCH 3/3] expanded Model.save example --- index.html | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index b879589c..e9a85f37 100644 --- a/index.html +++ b/index.html @@ -758,13 +758,16 @@ setInterval(function() {

- In the following example, notice how because the model has never been - saved previously, our overridden version of Backbone.sync receives a "create" request. + In the following example, notice how our overridden version + of Backbone.sync receives a "create" request + the first time the model is saved and an "update" + request the second time.

 Backbone.sync = function(method, model) {
   alert(method + ": " + JSON.stringify(model));
+  model.id = 1;
 };
 
 var book = new Backbone.Model({
@@ -773,6 +776,10 @@ var book = new Backbone.Model({
 });
 
 book.save();
+
+book.save({
+  author: "Teddy"
+});