Skip to content

Commit

Permalink
Merge pull request jashkenas#395 from lorensr/master
Browse files Browse the repository at this point in the history
Clarified/expanded examples; fixed typos.
  • Loading branch information
jashkenas committed Jul 1, 2011
2 parents b5112b4 + 2ed2af6 commit 1491d29
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
1 change: 0 additions & 1 deletion examples/todos/todos.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 24 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -761,13 +761,16 @@ <h2 id="Model">Backbone.Model</h2>
</p>

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

<pre class="runnable">
Backbone.sync = function(method, model) {
alert(method + ": " + JSON.stringify(model));
model.id = 1;
};

var book = new Backbone.Model({
Expand All @@ -776,6 +779,10 @@ <h2 id="Model">Backbone.Model</h2>
});

book.save();

book.save({
author: "Teddy"
});
</pre>

<p>
Expand Down Expand Up @@ -1145,15 +1152,25 @@ <h2 id="Collection">Backbone.Collection</h2>
</p>

<pre class="runnable">
var ships = new Backbone.Collection;
var Ship = Backbone.Model.extend({
defaults: {
"name": "Black Pearl"
}
});

var Fleet = Backbone.Collection.extend({
model: Ship
});

var pirates = new Fleet();

ships.bind("add", function(ship) {
pirates.bind("add", function(ship) {
alert("Ahoy " + ship.get("name") + "!");
});

ships.add([
pirates.add([
{name: "Flying Dutchman"},
{name: "Black Pearl"}
{captain: "Jack Sparrow"}
]);
</pre>

Expand Down Expand Up @@ -1588,7 +1605,7 @@ <h2 id="History">Backbone.history</h2>
<h2 id="Sync">Backbone.sync</h2>

<p>
<b>Backbone.sync</b> is the function the Backbone calls every time it
<b>Backbone.sync</b> is the function that Backbone calls every time it
attempts to read or save a model to the server. By default, it uses
<tt>(jQuery/Zepto).ajax</tt> to make a RESTful JSON request. You can override
it in order to use a different persistence strategy, such as WebSockets,
Expand Down

0 comments on commit 1491d29

Please sign in to comment.