[Pkg-javascript-commits] [backbone] 29/34: additional documentation ... getting ready for 0.1.2

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:58:45 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.1.2
in repository backbone.

commit b854b28d18d321733797fa4b382298c7cd053043
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Tue Oct 19 09:41:50 2010 -0400

    additional documentation ... getting ready for 0.1.2
---
 backbone.js  | 18 +++++++-------
 index.html   | 76 +++++++++++++++++++++++++++++++++++++++---------------------
 package.json |  2 +-
 3 files changed, 60 insertions(+), 36 deletions(-)

diff --git a/backbone.js b/backbone.js
index d77ba84..272a7e7 100644
--- a/backbone.js
+++ b/backbone.js
@@ -18,7 +18,7 @@
   }
 
   // Current version of the library. Keep in sync with `package.json`.
-  Backbone.VERSION = '0.1.1';
+  Backbone.VERSION = '0.1.2';
 
   // Require Underscore, if we're on the server, and it's not already present.
   var _ = this._;
@@ -116,10 +116,10 @@
   _.extend(Backbone.Model.prototype, Backbone.Events, {
 
     // A snapshot of the model's previous attributes, taken immediately
-    // after the last `changed` event was fired.
+    // after the last `"change"` event was fired.
     _previousAttributes : null,
 
-    // Has the item been changed since the last `changed` event?
+    // Has the item been changed since the last `"change"` event?
     _changed : false,
 
     // Return a copy of the model's `attributes` object.
@@ -132,7 +132,7 @@
       return this.attributes[attr];
     },
 
-    // Set a hash of model attributes on the object, firing `changed` unless you
+    // Set a hash of model attributes on the object, firing `"change"` unless you
     // choose to silence it.
     set : function(attrs, options) {
 
@@ -167,12 +167,12 @@
         }
       }
 
-      // Fire the `change` event, if the model has been changed.
+      // Fire the `"change"` event, if the model has been changed.
       if (!options.silent && this._changed) this.change();
       return this;
     },
 
-    // Remove an attribute from the model, firing `changed` unless you choose to
+    // Remove an attribute from the model, firing `"change"` unless you choose to
     // silence it.
     unset : function(attr, options) {
       options || (options = {});
@@ -258,7 +258,7 @@
       this._changed = false;
     },
 
-    // Determine if the model has changed since the last `changed` event.
+    // Determine if the model has changed since the last `"change"` event.
     // If you specify an attribute name, determine if that attribute has changed.
     hasChanged : function(attr) {
       if (attr) return this._previousAttributes[attr] != this.attributes[attr];
@@ -283,14 +283,14 @@
     },
 
     // Get the previous value of an attribute, recorded at the time the last
-    // `changed` event was fired.
+    // `"change"` event was fired.
     previous : function(attr) {
       if (!attr || !this._previousAttributes) return null;
       return this._previousAttributes[attr];
     },
 
     // Get all of the attributes of the model at the time of the previous
-    // `changed` event.
+    // `"change"` event.
     previousAttributes : function() {
       return _.clone(this._previousAttributes);
     }
diff --git a/index.html b/index.html
index cc75db2..8f7a35c 100644
--- a/index.html
+++ b/index.html
@@ -252,11 +252,11 @@
 
     <table>
       <tr>
-        <td><a href="backbone.js">Development Version (0.1.1)</a></td>
+        <td><a href="backbone.js">Development Version (0.1.2)</a></td>
         <td><i>21kb, Uncompressed with Comments</i></td>
       </tr>
       <tr>
-        <td><a href="backbone-min.js">Production Version (0.1.1)</a></td>
+        <td><a href="backbone-min.js">Production Version (0.1.2)</a></td>
         <td><i>2kb, Packed and Gzipped</i></td>
       </tr>
     </table>
@@ -439,7 +439,7 @@ sidebar.promptColor();
 
 <pre>
 var Note = Backbone.Model.extend({
-  
+
   initialize: function() { ... },
 
   author: function() { ... },
@@ -460,7 +460,7 @@ var Note = Backbone.Model.extend({
         parent object's implementation, you'll have to explicitly call it, along these lines:
       </i>
     </p>
-    
+
 <pre>
 var Note = Backbone.Model.extend({
   set: function(attributes, options) {
@@ -578,7 +578,7 @@ alert(JSON.stringify(artist));
       <tt>success</tt> and <tt>error</tt> callbacks in the options hash, which
       are passed <tt>(model, response)</tt> as arguments.
     </p>
-    
+
 <pre>
 // Poll every 10 seconds to keep the channel model up-to-date.
 setInterval(function() {
@@ -774,17 +774,17 @@ bill.set({name : "Bill Jones"});
       providing instance <b>properties</b>, as well as optional <b>classProperties</b> to be attached
       directly to the collection's constructor function.
     </p>
-    
+
     <p id="Collection-model">
       <b class="header">model</b><code>collection.model</code>
       <br />
-      Override this property to specify the model class that the collection 
-      contains. If defined, you can pass raw attributes objects (and arrays) to 
+      Override this property to specify the model class that the collection
+      contains. If defined, you can pass raw attributes objects (and arrays) to
       <a href="#Collection-add">add</a>, <a href="#Collection-create">create</a>,
       and <a href="#Collection-refresh">refresh</a>, and the attributes will be
       converted into a model of the proper type.
     </p>
-    
+
 <pre>
 var Library = Backbone.Collection.extend({
   model: Book
@@ -974,7 +974,7 @@ alert(chapters.pluck('title'));
       <br />
       Force a collection to re-sort itself. You don't need to call this under
       normal circumstances, as a collection with a <a href="#Collection-comparator">comparator</a> function
-      will maintain itself in proper sort order at all times. Calling <b>sort</b> 
+      will maintain itself in proper sort order at all times. Calling <b>sort</b>
       triggers the collection's <tt>"refresh"</tt> event, unless silenced by passing
       <tt>{silent: true}</tt>
     </p>
@@ -1036,9 +1036,9 @@ var Notes = Backbone.Collection.extend({
     <p>
       The server handler for <b>fetch</b> requests should return a JSON list of
       models, namespaced under "models": <tt>{"models": [...]}</tt> —
-      instead of returning the 
-      array directly, we ask you to namespace your models like this by default, 
-      so that it's possible to send down out-of-band information 
+      instead of returning the
+      array directly, we ask you to namespace your models like this by default,
+      so that it's possible to send down out-of-band information
       for things like pagination or error states.
     </p>
 
@@ -1060,7 +1060,7 @@ Accounts.fetch();
       for interfaces that are not needed immediately: for example, documents
       with collections of notes that may be toggled open and closed.
     </p>
-    
+
     <p id="Collection-refresh">
       <b class="header">refresh</b><code>collection.refresh(models, [options])</code>
       <br />
@@ -1070,12 +1070,12 @@ Accounts.fetch();
       of models (or attribute hashes), triggering a single <tt>"refresh"</tt> event
       at the end. Pass <tt>{silent: true}</tt> to suppress the <tt>"refresh"</tt> event.
     </p>
-    
+
     <p>
       Here's an example using <b>refresh</b> to bootstrap a collection during initial page load,
       in a Rails application.
     </p>
-    
+
 <pre>
 <script>
   Accounts.refresh(<%= @accounts.to_json %>);
@@ -1138,8 +1138,32 @@ var othello = NYPL.create({
     </p>
 
     <p>
-      For example, a Rails handler responding to an <tt>"update"</tt> call from
-      <b>Backbone.sync</b> would look like this: <i>(In real code, never use
+      The default <b>sync</b> handler maps CRUD to REST like so:
+    </p>
+
+    <ul>
+      <li><b>create → POST   </b><tt>/collection</tt></li>
+      <li><b>read → GET   </b><tt>/collection[/id]</tt></li>
+      <li><b>update → PUT   </b><tt>/collection/id</tt></li>
+      <li><b>delete → DELETE   </b><tt>/collection/id</tt></li>
+    </ul>
+
+    <p>
+      If your web server makes it difficult to work with real <tt>PUT</tt> and
+      <tt>DELETE</tt> requests, you may choose to emulate them instead, using
+      HTTP <tt>POST</tt>, and passing them under the <tt>_method</tt> parameter
+      instead, by turning on <tt>Backbone.emulateHttp</tt>:
+    </p>
+    
+<pre>
+Backbone.emulateHttp = true;
+
+model.save();  // Sends a POST to "/collection/id", with "_method=PUT"
+</pre>
+
+    <p>
+      As an example, a Rails handler responding to an <tt>"update"</tt> call from
+      <b>Backbone.sync</b> might look like this: <i>(In real code, never use
       </i><tt>update_attributes</tt><i> blindly, and always whitelist the attributes
       you allow to be changed.)</i>
     </p>
@@ -1189,7 +1213,7 @@ var DocumentRow = Backbone.View.extend({
     "click .button.edit":   "openEditDialog",
     "click .button.delete": "destroy"
   },
-  
+
   initialize: function() {
     _.bindAll(this, "render");
   },
@@ -1209,7 +1233,7 @@ var DocumentRow = Backbone.View.extend({
       options that, if passed, will be attached directly to the view:
       <tt>model</tt>, <tt>collection</tt>,
       <tt>el</tt>, <tt>id</tt>, <tt>className</tt>, and <tt>tagName</tt>.
-      If the view defines an <b>initialize</b> function, it will be called when 
+      If the view defines an <b>initialize</b> function, it will be called when
       the view is first created. If you'd like to create a view that references
       an element <i>already</i> in the DOM, pass in the element as an option:
       <tt>new View({el: existingElement})</tt>
@@ -1284,18 +1308,18 @@ var Bookmark = Backbone.View.extend({
       Backbone is agnostic with respect to your preferred method of HTML templating.
       Your <b>render</b> function could even munge together an HTML string, or use
       <tt>document.createElement</tt> to generate a DOM tree. However, we suggest
-      choosing a nice JavaScript templating library. 
-      <a href="http://github.com/janl/mustache.js">Mustache.js</a>, 
+      choosing a nice JavaScript templating library.
+      <a href="http://github.com/janl/mustache.js">Mustache.js</a>,
       <a href="http://github.com/creationix/haml-js">Haml-js</a>, and
-      <a href="http://github.com/sstephenson/eco">Eco</a> are all fine alternatives. 
+      <a href="http://github.com/sstephenson/eco">Eco</a> are all fine alternatives.
       Because <a href="http://documentcloud.github.com/underscore/">Underscore.js</a> is already on the page,
       <a href="http://documentcloud.github.com/underscore/#template">_.template</a>
       is available, and is an excellent choice if you've already XSS-sanitized
       your interpolated data.
     </p>
-    
+
     <p>
-      Whatever templating strategy you end up with, it's nice if you <i>never</i> 
+      Whatever templating strategy you end up with, it's nice if you <i>never</i>
       have to put strings of HTML in your JavaScript. At DocumentCloud, we
       use <a href="http://documentcloud.github.com/jammit/">Jammit</a> in order
       to package up JavaScript templates stored in <tt>/app/views</tt> as part
@@ -1378,7 +1402,7 @@ var DocumentView = Backbone.View.extend({
 </pre>
 
     <h2 id="changelog">Change Log</h2>
-    
+
     <p>
       <b class="header">0.1.1</b> — <small><i>Oct 14, 2010</i></small><br />
       Added a convention for <tt>initialize</tt> functions to be called
diff --git a/package.json b/package.json
index ce8a5e5..c2485b8 100644
--- a/package.json
+++ b/package.json
@@ -10,5 +10,5 @@
   },
   "lib"           : ".",
   "main"          : "backbone.js",
-  "version"       : "0.1.1"
+  "version"       : "0.1.2"
 }

-- 
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