Skip to content
Browse files

Merge branch 'master' of github.com:documentcloud/backbone

  • Loading branch information...
2 parents 17277f0 + 26efd06 commit 4086a42ffc45dedb097daec0a29edd48f270e489 @jashkenas jashkenas committed
Showing with 28 additions and 2 deletions.
  1. +1 −0 backbone.js
  2. +11 −2 index.html
  3. +16 −0 test/collection.js
View
1 backbone.js
@@ -567,6 +567,7 @@
// its models in sort order, as they're added and removed.
var Collection = Backbone.Collection = function(models, options) {
options || (options = {});
+ if (options.url) this.url = options.url;
if (options.model) this.model = options.model;
if (options.comparator !== void 0) this.comparator = options.comparator;
this._reset();
View
13 index.html
@@ -1522,11 +1522,16 @@ <h2 id="Collection">Backbone.Collection</h2>
may be included as an option. Passing <tt>false</tt> as the
comparator option will prevent sorting. If you define an
<b>initialize</b> function, it will be invoked when the collection is
- created.
+ created. There are several options that, if provided, are attached to the
+ collection directly: <tt>url</tt>, <tt>model</tt> and <tt>comparator</tt>.
</p>
<pre>
var tabs = new TabSet([tab1, tab2, tab3]);
+var spaces = new Backbone.Collection([], {
+ model: Space,
+ url: '/spaces'
+});
</pre>
<p id="Collection-models">
@@ -3838,13 +3843,17 @@ <h2 id="faq">F.A.Q.</h2>
<h2 id="changelog">Change Log</h2>
- <b class="header">Edge</b> &mdash; <small><i>Unreleased</i></small><br/>
+ <b class="header">Edge</b> &mdash; <small><i>Unreleased</i></small> &mdash; <a href="https://github.com/documentcloud/backbone/compare/0.9.10...master">Diff</a><br/>
<ul style="margin-top: 5px;">
<li>
The <tt>silent</tt> option has been removed from <tt>Model#set</tt>.
Custom options should be used to accomplish this effect instead.
</li>
+ <li>
+ Constructing a new collection with a <tt>url</tt> option will attach it
+ to the new instance.
+ </li>
</ul>
<b class="header">0.9.10</b> &mdash; <small><i>Jan. 15, 2013</i></small> &mdash; <a href="https://github.com/documentcloud/backbone/compare/0.9.9...0.9.10">Diff</a><br />
View
16 test/collection.js
@@ -1049,4 +1049,20 @@ $(document).ready(function() {
collection.add(collection.models, {merge: true}); // don't sort
});
+ test("Attach options to collection.", 3, function() {
+ var url = '/somewhere';
+ var model = new Backbone.Model;
+ var comparator = function(){};
+
+ var collection = new Backbone.Collection([], {
+ url: url,
+ model: model,
+ comparator: comparator
+ });
+
+ strictEqual(collection.url, url);
+ ok(collection.model === model);
+ ok(collection.comparator === comparator);
+ });
+
});

0 comments on commit 4086a42

Please sign in to comment.
Something went wrong with that request. Please try again.