Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.

Commit a2b924c

Browse files
committed
Lots of edits -- running well under Node.js
1 parent 317c99b commit a2b924c

File tree

3 files changed

+42
-35
lines changed

3 files changed

+42
-35
lines changed

README

+3
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ http://github.com/documentcloud/backbone/issues/
2020

2121
All contributors are listed here:
2222
http://github.com/documentcloud/backbone/contributors
23+
24+
Special thanks to Robert Kieffer for the original philosophy behind Backbone.
25+
http://github.com/broofa

backbone.js

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
// Export for both CommonJS and the Browser.
1818
(typeof exports !== 'undefined' ? exports : this).Backbone = Backbone;
1919

20+
// Require Underscore, if we're on the server.
21+
var _ = this._;
22+
if (!_ && (typeof require !== 'undefined')) _ = require("underscore")._;
23+
2024
// Helper function to correctly set up the prototype chain, for subclasses.
2125
// Similar to `goog.inherits`, but uses a hash of prototype properties and
2226
// static properties to be extended.

index.html

+35-35
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,7 @@
232232
<p>
233233
<i>
234234
Backbone is an open-source component of
235-
<a href="http://documentcloud.org/">DocumentCloud</a>.<br />
236-
Special thanks to <a href="http://github.com/broofa">Robert Kieffer</a>
237-
for inspiring the ideas behind this library.
235+
<a href="http://documentcloud.org/">DocumentCloud</a>.
238236
</i>
239237
</p>
240238

@@ -246,7 +244,7 @@ <h2 id="downloads">
246244
<table>
247245
<tr>
248246
<td><a href="backbone.js">Development Version (0.1.0)</a></td>
249-
<td><i>22kb, Uncompressed with Comments</i></td>
247+
<td><i>21kb, Uncompressed with Comments</i></td>
250248
</tr>
251249
<tr>
252250
<td><a href="backbone-min.js">Production Version (0.1.0)</a></td>
@@ -267,8 +265,8 @@ <h2 id="downloads">
267265
<h2 id="Introduction">Introduction</h2>
268266

269267
<p>
270-
When working on a heavy-duty JavaScript application, one of the first things
271-
you learn is to stop tying your data to the DOM. It's all
268+
When working on a web application that involved a lot of JavaScript, one
269+
of the first things you learn is to stop tying your data to the DOM. It's all
272270
too easy to create JavaScript applications that end up as tangled piles of
273271
jQuery selectors and callbacks, all trying frantically to keep data in
274272
sync between the HTML UI, your JavaScript logic, and the database on your
@@ -281,7 +279,7 @@ <h2 id="Introduction">Introduction</h2>
281279
<a href="#Model">Models</a>, which can be created, validated, destroyed,
282280
and saved to the server. Whenever a UI action causes an attribute of
283281
a model to change, the model triggers a <i>"change"</i> event; all
284-
the <a href="#View">Views</a> that reference the model's data receive the
282+
the <a href="#View">Views</a> that display the model's data receive the
285283
event, causing them to re-render. You don't have to write the glue
286284
code that looks into the DOM to find an element with a specific <i>id</i>,
287285
and update the HTML manually
@@ -353,8 +351,8 @@ <h2 id="Events">Backbone.Events</h2>
353351
</p>
354352

355353
<pre>
356-
object.bind("all", function(eventName) {
357-
proxy.trigger(eventName);
354+
proxy.bind("all", function(eventName) {
355+
object.trigger(eventName);
358356
});
359357
</pre>
360358

@@ -379,7 +377,7 @@ <h2 id="Events">Backbone.Events</h2>
379377
<b class="header">trigger</b><code>object.trigger(event, [*args])</code>
380378
<br />
381379
Trigger all callbacks for the given <b>event</b>. All subsequent arguments to
382-
<b>trigger</b> will be passed along.
380+
<b>trigger</b> will be passed along to the event callbacks.
383381
</p>
384382

385383
<h2 id="Model">Backbone.Model</h2>
@@ -394,8 +392,8 @@ <h2 id="Model">Backbone.Model</h2>
394392

395393
<p>
396394
The following is a contrived example, but it demonstrates defining a model
397-
with a custom method, setting an attribute, and firing an event when a
398-
specific property of the model changes.
395+
with a custom method, setting an attribute, and firing an event keyed
396+
to changes in that specific attribute.
399397
After running this code once, <tt>sidebar</tt> will be
400398
available in your browser's console, so you can play around with it.
401399
</p>
@@ -420,11 +418,11 @@ <h2 id="Model">Backbone.Model</h2>
420418
</pre>
421419

422420
<p id="Model-extend">
423-
<b class="header">extend</b><code>Backbone.Model.extend(properties, [staticProperties])</code>
421+
<b class="header">extend</b><code>Backbone.Model.extend(properties, [classProperties])</code>
424422
<br />
425423
To create a <b>Model</b> class of your own, you extend <b>Backbone.Model</b>
426-
and provide instance <b>properties</b>, as well as optional properties to be attached
427-
directly to the constructor function.
424+
and provide instance <b>properties</b>, as well as optional
425+
<b>classProperties</b> to be attached directly to the constructor function.
428426
</p>
429427

430428
<p>
@@ -456,18 +454,17 @@ <h2 id="Model">Backbone.Model</h2>
456454
<br />
457455
Set a hash of attributes (one or many) on the model. If any of the attributes
458456
change the models state, a <tt>"change"</tt> event will be fired, unless
459-
<tt>silent</tt> is passed as an option.
457+
<tt>{silent: true}</tt> is passed as an option.
460458
</p>
461459

462460
<p>
463-
If the model has a <tt>validate</tt> method, it will be validated before
464-
the attributes are set, and no changes will occur if the validation fails.
461+
If the model has a <a href="#Model-validate">validate</a> method,
462+
it will be validated before the attributes are set, and no changes will
463+
occur if the validation fails.
465464
</p>
466465

467466
<pre>
468467
note.set({title: "October 12", content: "Lorem Ipsum Dolor Sit Amet..."});
469-
470-
note.set({title: "October 31"}, {silent: true});
471468
</pre>
472469

473470
<p id="Model-unset">
@@ -501,15 +498,15 @@ <h2 id="Model">Backbone.Model</h2>
501498
<b class="header">attributes</b><code>model.attributes</code>
502499
<br />
503500
The <b>attributes</b> property is the internal hash containing the model's
504-
state. Please use <tt>set</tt> to update the attributes instead of modifying
501+
state. Please use <a href="#Model-set">set</a> to update the attributes instead of modifying
505502
them directly. If you'd like to retrieve and munge a copy of the model's
506-
attributes, use <tt>toJSON</tt> instead.
503+
attributes, use <a href="#Model-toJSON">toJSON</a> instead.
507504
</p>
508505

509506
<p id="Model-toJSON">
510507
<b class="header">toJSON</b><code>model.toJSON</code>
511508
<br />
512-
Return a copy of the model's <b>attributes</b> for JSON stringification.
509+
Return a copy of the model's <a href="#Model-attributes">attributes</a> for JSON stringification.
513510
This can be used for persistence, serialization, or for augmentation before
514511
being handed off to a view.
515512
</p>
@@ -529,16 +526,18 @@ <h2 id="Model">Backbone.Model</h2>
529526
<b class="header">save</b><code>model.save(attributes, [options])</code>
530527
<br />
531528
Save a model to your database (or alternative persistence layer),
532-
by delegating to <tt>Backbone.sync</tt>. If the model has a <tt>validate</tt>
529+
by delegating to <a href="#Sync">Backbone.sync</a>. If the model has a <a href="#Model-validate">validate</a>
533530
method, and validation fails, the model will not be saved. If the model
534-
<tt>isNew()</tt>, the save will be an HTTP <tt>POST</tt>, if the model already
535-
exists on the server, the save will be a <tt>PUT</tt>. Accepts
536-
<tt>success</tt> and <tt>error</tt> callbacks in the options hash.
531+
<a href="#Model-isNew">isNew</a>, the save will be a <tt>"create"</tt>
532+
(HTTP <tt>POST</tt>), if the model already
533+
exists on the server, the save will be an <tt>"update"</tt> (HTTP <tt>PUT</tt>). Accepts
534+
<tt>success</tt> and <tt>error</tt> callbacks in the options hash, which
535+
are passed <tt>(model, response)</tt> as arguments.
537536
</p>
538537

539538
<p>
540539
In the following example, notice how because the model has never been
541-
saved previously, <tt>Backbone.sync</tt> receives a <tt>"create"</tt> request.
540+
saved previously, our overridden version of <tt>Backbone.sync</tt> receives a <tt>"create"</tt> request.
542541
</p>
543542

544543
<pre class="runnable">
@@ -558,7 +557,7 @@ <h2 id="Model">Backbone.Model</h2>
558557
<b class="header">destroy</b><code>model.destroy([options])</code>
559558
<br />
560559
Destroys the model on the server by delegating an HTTP <tt>DELETE</tt>
561-
request to <tt>Backbone.sync</tt>. Accepts
560+
request to <a href="#Sync">Backbone.sync</a>. Accepts
562561
<tt>success</tt> and <tt>error</tt> callbacks in the options hash.
563562
</p>
564563

@@ -616,14 +615,14 @@ <h2 id="Model">Backbone.Model</h2>
616615

617616
<p>
618617
A model with an id of <tt>101</tt>, stored in a
619-
<b>Backbone.Collection</b> with a <tt>url</tt> of <tt>"/notes"</tt>,
618+
<a href="#Collection">Backbone.Collection</a> with a <tt>url</tt> of <tt>"/notes"</tt>,
620619
would have this URL: <tt>"/notes/101"</tt>
621620
</p>
622621

623622
<p id="Model-clone">
624623
<b class="header">clone</b><code>model.clone()</code>
625624
<br />
626-
Create a new instance of a model with identical attributes.
625+
Returns a new instance of the model with identical attributes.
627626
</p>
628627

629628
<p id="Model-isNew">
@@ -636,9 +635,10 @@ <h2 id="Model">Backbone.Model</h2>
636635
<p id="Model-change">
637636
<b class="header">change</b><code>model.change()</code>
638637
<br />
639-
If you've been passing <tt>{silent: true}</tt> to <tt>set</tt> in order to
640-
aggregate rapid changes to a model, you'll want to fire the <tt>"change"</tt>
641-
event when you're finished. Call <tt>model.change()</tt> to trigger it.
638+
Manually trigger the <tt>"change"</tt> event.
639+
If you've been passing <tt>{silent: true}</tt> to the <a href="#Model-set">set</a> function in order to
640+
aggregate rapid changes to a model, you'll want to call <tt>model.change()</tt>
641+
when you're all finished.
642642
</p>
643643

644644
<p id="Model-hasChanged">
@@ -712,7 +712,7 @@ <h2 id="Collection">Backbone.Collection</h2>
712712
</p>
713713

714714
<p id="Collection-extend">
715-
<b class="header">extend</b><code>Backbone.Collection.extend(properties, [staticProperties])</code>
715+
<b class="header">extend</b><code>Backbone.Collection.extend(properties, [classProperties])</code>
716716
<br />
717717
To create a <b>Collection</b> class of your own, extend <b>Backbone.Collection</b>,
718718
providing instance <b>properties</b>, as well as optional properties to be attached

0 commit comments

Comments
 (0)