[Pkg-javascript-commits] [backbone] 64/101: removing Backbone.Model#isEqual
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 16:58:29 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.1.0
in repository backbone.
commit c14dde7c207eb1d91c8829ffa4f190bb3fb84aa6
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date: Tue Oct 12 11:01:38 2010 -0400
removing Backbone.Model#isEqual
---
backbone.js | 14 +++++++-------
index.html | 23 +++++++++++++++++++++--
test/model.js | 9 ---------
3 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/backbone.js b/backbone.js
index 9b2a3af..c52318a 100644
--- a/backbone.js
+++ b/backbone.js
@@ -32,6 +32,11 @@
return child;
};
+ // Get a url as a property or as a function.
+ var getUrl = function(object) {
+ return _.isFunction(object.url) ? object.url() : object.url;
+ };
+
// Backbone.Events
// -----------------
@@ -136,7 +141,7 @@
// using Backbone's restful methods, override this to change the endpoint
// that will be called.
url : function() {
- var base = this.collection.url();
+ var base = getUrl(this.collection);
if (this.isNew()) return base;
return base + '/' + this.id;
},
@@ -152,11 +157,6 @@
return new (this.constructor)(this.attributes());
},
- // Are this model's attributes identical to another model?
- isEqual : function(other) {
- return other && _.isEqual(this._attributes, other._attributes);
- },
-
// A model is new if it has never been saved to the server, and has a negative
// ID.
isNew : function() {
@@ -621,7 +621,7 @@
//
Backbone.sync = function(type, model, success, error) {
$.ajax({
- url : model.url(),
+ url : getUrl(model),
type : type,
data : {model : model},
dataType : 'json',
diff --git a/index.html b/index.html
index a059e5b..42c0a6b 100644
--- a/index.html
+++ b/index.html
@@ -167,6 +167,7 @@
<li>– <a href="#Collection-getIds">getIds</a></li>
<li>– <a href="#Collection-at">at</a></li>
<li>– <a href="#Collection-sort">sort</a></li>
+ <li>– <a href="#Model-url">url</a></li>
<li>– <a href="#Collection-refresh">refresh</a></li>
<li>– <a href="#Collection-fetch">fetch</a></li>
<li>– <a href="#Collection-create">create</a></li>
@@ -510,8 +511,26 @@ one.set({
});
</pre>
-
-
+ <p id="Model-url">
+ <b class="header">url</b><code>model.url()</code>
+ <br />
+ Returns the relative URL where the model's resource would be located on
+ the server. If your models are located somewhere else, override this method
+ with the correct logic. Generates URLs of the form: <tt>"/[collection]/[id]"</tt>.
+ </p>
+
+ <p>
+ A model with an id of <tt>101</tt>, stored in a
+ <tt>Bindable.Collection</tt> with a <tt>url</tt> of <tt>"/notes"</tt>,
+ would have this URL: <tt>"/notes/101"</tt>
+ </p>
+
+ <p id="Model-clone">
+ <b class="header">clone</b><code>model.clone()</code>
+ <br />
+ Create a new instance of a model with identical attributes.
+ </p>
+
diff --git a/test/model.js b/test/model.js
index 0bd9138..01f7d60 100644
--- a/test/model.js
+++ b/test/model.js
@@ -54,15 +54,6 @@ $(document).ready(function() {
equals(b.get('foo'), 1, "Changing a parent attribute does not change the clone.");
});
- test("model: isEqual", function() {
- attrs = { 'foo': 1, 'bar': 2, 'baz': 3};
- a = new Backbone.Model(attrs);
- b = new Backbone.Model(attrs);
- ok(a.isEqual(b), "a should equal b");
- c = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3, 'qux': 4});
- ok(!a.isEqual(c), "a should not equal c");
- });
-
test("model: isNew", function() {
attrs = { 'foo': 1, 'bar': 2, 'baz': 3};
a = new Backbone.Model(attrs);
--
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