From c14dde7c207eb1d91c8829ffa4f190bb3fb84aa6 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Tue, 12 Oct 2010 11:01:38 -0400 Subject: [PATCH] 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 9b2a3af9..c52318a0 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 a059e5b3..42c0a6b7 100644 --- a/index.html +++ b/index.html @@ -167,6 +167,7 @@
  • getIds
  • at
  • sort
  • +
  • url
  • refresh
  • fetch
  • create
  • @@ -510,8 +511,26 @@ one.set({ }); - - +

    + urlmodel.url() +
    + 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: "/[collection]/[id]". +

    + +

    + A model with an id of 101, stored in a + Bindable.Collection with a url of "/notes", + would have this URL: "/notes/101" +

    + +

    + clonemodel.clone() +
    + Create a new instance of a model with identical attributes. +

    + diff --git a/test/model.js b/test/model.js index 0bd91381..01f7d607 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);