From 3bfbcd4123a19f9ec31c5d64d3d4322140adc2fa Mon Sep 17 00:00:00 2001
From: Genadi Samokovarov
Date: Mon, 25 Mar 2013 20:58:32 +0200
Subject: [PATCH 1/2] Don't accept urlRoot from Model and url from Collection
---
backbone.js | 6 +-----
test/collection.js | 5 +----
test/model.js | 5 -----
3 files changed, 2 insertions(+), 14 deletions(-)
diff --git a/backbone.js b/backbone.js
index 8f38f5bb7..68090b96a 100644
--- a/backbone.js
+++ b/backbone.js
@@ -248,7 +248,7 @@
options || (options = {});
this.cid = _.uniqueId('c');
this.attributes = {};
- _.extend(this, _.pick(options, modelOptions));
+ if (options.collection) this.collection = options.collection;
if (options.parse) attrs = this.parse(attrs, options) || {};
if (defaults = _.result(this, 'defaults')) {
attrs = _.defaults({}, attrs, defaults);
@@ -258,9 +258,6 @@
this.initialize.apply(this, arguments);
};
- // A list of options to be attached directly to the model, if provided.
- var modelOptions = ['urlRoot', 'collection'];
-
// Attach all inheritable methods to the Model prototype.
_.extend(Model.prototype, Events, {
@@ -596,7 +593,6 @@
// 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();
diff --git a/test/collection.js b/test/collection.js
index d068b3961..ce272ff5f 100644
--- a/test/collection.js
+++ b/test/collection.js
@@ -1081,18 +1081,15 @@ $(document).ready(function() {
collection.add(collection.models, {merge: true}); // don't sort
});
- test("Attach options to collection.", 3, function() {
- var url = '/somewhere';
+ test("Attach options to collection.", 2, function() {
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);
});
diff --git a/test/model.js b/test/model.js
index 620a9917a..345b82665 100644
--- a/test/model.js
+++ b/test/model.js
@@ -111,11 +111,6 @@ $(document).ready(function() {
equal(model.url(), '/nested/1/collection/2');
});
- test('urlRoot is directly attached if passed in the options', 1, function () {
- var model = new Backbone.Model({a: 2}, {urlRoot: '/test'});
- equal(model.urlRoot, '/test');
- });
-
test("underscore methods", 5, function() {
var model = new Backbone.Model({ 'foo': 'a', 'bar': 'b', 'baz': 'c' });
var model2 = model.clone();
From 5b8f794272a63355b230a9fd960783906581077f Mon Sep 17 00:00:00 2001
From: Genadi Samokovarov
Date: Mon, 25 Mar 2013 23:12:51 +0200
Subject: [PATCH 2/2] Remove the redundant documentation bits
---
index.html | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/index.html b/index.html
index cad0fa61e..f6d44cbb3 100644
--- a/index.html
+++ b/index.html
@@ -987,11 +987,6 @@ Backbone.Model
otherwise added automatically when you first add a model to a collection.
-
- {urlRoot: "..."} option may be passed when creating a new model
- that needs to have a custom one-off URL endpoint.
-
-
If {parse: true} is passed as an option, the attributes
will first be converted by parse before being
@@ -1609,8 +1604,8 @@
Backbone.Collection
may be included as an option. Passing false as the
comparator option will prevent sorting. If you define an
initialize function, it will be invoked when the collection is
- created. There are several options that, if provided, are attached to the
- collection directly: url, model and comparator.
+ created. There are a couple of options that, if provided, are attached to
+ the collection directly: model and comparator.