Backbone 1.0.0 #303

Merged
merged 7 commits into from Mar 22, 2013

Projects

None yet

5 participants

@philfreo
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 Mar 21, 2013
@philfreo philfreo Allow collectionType to fallback to generic Backbone.Collection.
Fixes tests / functionality broken by 8bfdf03 / #294
f120fa1
@philfreo Erick Ruiz de Chavez Collection.update is now Collection.set
Collection.update is now Collection.set on Backbone 1.0.0
9ddeae1
@philfreo Erick Ruiz de Chavez Update package.json
Collection.update is now Collection.set on Backbone 1.0.0 
810c0fc
@philfreo Erick Ruiz de Chavez Update index.html
Collection.update is now Collection.set on Backbone 1.0.0 
671d0da
@philfreo philfreo Collection#update -> Collection#set in tests 923bbaa
@philfreo philfreo Backbone 1.0.0 in tests/lib 6fce9d7
@philfreo philfreo Fail earlier if failing f3bd69f

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.

Owner

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

@PaulUithol PaulUithol merged commit a9e5a89 into PaulUithol:master Mar 22, 2013
Owner

Fully compatible now, with the latest commit!

Collaborator

Fully compatible now, with the latest commit!

Awesome thanks!!

Thanks!

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.

Collaborator

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

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"
      }
    ]
  }
}
Collaborator

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

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).

Collaborator

Submitted a failing testcase in #311

gorman commented Apr 8, 2013

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