Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Backbone 1.0.0 #303

Merged
merged 7 commits into from

5 participants

Phil Freo Fernando Tapia Rico Paul Uithol centaure David Gorman
Phil Freo
Collaborator

This isn't complete, but goes further than #297

Reverse relations are failing everywhere at the moment - not sure why.

philfreo and others added some commits
Phil Freo philfreo Allow collectionType to fallback to generic Backbone.Collection.
Fixes tests / functionality broken by 8bfdf03 / #294
f120fa1
Erick Ruiz de Chavez Collection.update is now Collection.set
Collection.update is now Collection.set on Backbone 1.0.0
9ddeae1
Erick Ruiz de Chavez Update package.json
Collection.update is now Collection.set on Backbone 1.0.0 
810c0fc
Erick Ruiz de Chavez Update index.html
Collection.update is now Collection.set on Backbone 1.0.0 
671d0da
Phil Freo philfreo Collection#update -> Collection#set in tests 923bbaa
Phil Freo philfreo Backbone 1.0.0 in tests/lib 6fce9d7
Phil Freo philfreo Fail earlier if failing f3bd69f
Fernando Tapia Rico

Hi,

it's not working when passing "reset" flag (Collection.fetch({ reset: true }) due to Collection.parse function is not being called with the JSON response.

Paul Uithol
Owner

Okay, merging this; will look into the remaining issues.

Paul Uithol PaulUithol merged commit a9e5a89 into from
Paul Uithol
Owner

Fully compatible now, with the latest commit!

Phil Freo
Collaborator

Fully compatible now, with the latest commit!

Awesome thanks!!

Fernando Tapia Rico

Thanks!

Fernando Tapia Rico

Sorry Paul,

Collection.parse is still being called with improper data. I'm using the current dev version (0.8.0+).
I've been trying to solve it myself, but it's a lot of code to just get used to in a few hours :) (but on my way to start contributing).
Thanks in advance.

Phil Freo
Collaborator

@fertapric can you provide a reduced test case of what you think the problem is?

Fernando Tapia Rico

Hi @philfreo,

I just uploaded a simple test at: https://dl.dropbox.com/u/17178183/test.html

The test is pretty simple, it just fetch some data from the server and prints the arguments passed to the "parse" function.

<html>

  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js" type="text/javascript"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js" type="text/javascript"></script>

    <script src="https://raw.github.com/PaulUithol/Backbone-relational/master/backbone-relational.js" type="text/javascript"></script>

    <script type="text/javascript">

      var Item = Backbone.RelationalModel.extend({

        parse: function(response, options) {
          return response;
        }

      });


      var Collection = Backbone.Collection.extend({

        model: Item,

        url: "https://dl.dropbox.com/u/17178183/test.json",

        parse: function(response, options) {
          console.log(response);
          return response;
        }

      });

      var testCollection = new Collection();

      var test = function() {
        testCollection.fetch({ reset: true });
      }

    </script>

  </head>

  <body>
    <a href="javascript: test();">
      Test
    </a>
  </body>

</html>

and here is the data, accesible at: https://dl.dropbox.com/u/17178183/test.json


{
  "response" : {
    "skip" : 0,
    "limit" : 5,
    "total" : 50,
    "last" : false,
    "items" : [
      {
        "id" : 1,
        "name" : "test1"
      },
      {
        "id" : 2,
        "name" : "test2"
      },
      {
        "id" : 3,
        "name" : "test3"
      },
      {
        "id" : 4,
        "name" : "test4"
      },
      {
        "id" : 5,
        "name" : "test5"
      }
    ]
  }
}
Phil Freo
Collaborator

hmmm yeah that does look like a problem... like Collection#parse is getting passed the collection instead of the response?

centaure

The following may help u guys (maybe):

I tried running @fertapric code with and without reset:true for both the v0.9.10 and v1.0.0 of backbone. For both reset: true and without reset:

(a) For Backbone v0.9.10 and Backbone-relational v0.8.0, the collection parse function receives the raw response object. And the collection parse function is called before the model parse function (which also receives an identical raw response object).

(b) For Backbone v1.0.0 and Backbone-relational v0.8.0+, the collection parse function receives an array consisting of one child --> Surrogate helper class (i.e. I believe it is the helper class in Backbone that is used for prototype chaining with 'extend'). And the collection parse function is called after the model parse function (the model parse function receive a raw response object similar to (a) above).

The following is some implementation detail that I also noticed (not sure if this is something that you already know about):

For both (a) and (b) (i.e. when the Collection's model type is Backbone.RelationalModel):
Backbone.js's Backbone.Collection.set/add ('set' in 1.0.0 and 'add' in 0.9.10) is being called twice during the fetch, and the model's parse function is also being called twice (the collection's parse function is only called once)

On the other hand, when the Collection's model type is Backbone.Model:
Backbone.js's Backbone.Collection.set/add is being called once during the fetch, and the model's parse function is also only being called once too (the collection parse function is also only called once). Note that in this case, the collection parse function is called before the model parse function and both parse functions receive an identical raw response object (as in (a) above).

Phil Freo
Collaborator

Submitted a failing testcase in #311

David Gorman

Just to add my +1, I'm experiencing this issue as well (using the latest code from master + Backbone 1.0). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 21, 2013
  1. Phil Freo

    Allow collectionType to fallback to generic Backbone.Collection.

    philfreo authored
    Fixes tests / functionality broken by 8bfdf03 / #294
  2. Phil Freo

    Collection.update is now Collection.set

    Erick Ruiz de Chavez authored philfreo committed
    Collection.update is now Collection.set on Backbone 1.0.0
  3. Phil Freo

    Update package.json

    Erick Ruiz de Chavez authored philfreo committed
    Collection.update is now Collection.set on Backbone 1.0.0 
  4. Phil Freo

    Update index.html

    Erick Ruiz de Chavez authored philfreo committed
    Collection.update is now Collection.set on Backbone 1.0.0 
  5. Phil Freo
  6. Phil Freo

    Backbone 1.0.0 in tests/lib

    philfreo authored
  7. Phil Freo

    Fail earlier if failing

    philfreo authored
Something went wrong with that request. Please try again.