mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-23 22:08:04 -05:00
removing Backbone.Model#isEqual
This commit is contained in:
14
backbone.js
14
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',
|
||||
|
||||
23
index.html
23
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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user