Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isLoaded to RecordArray for findMany and findAll #271

Closed
wants to merge 3 commits into from

Conversation

mmpestorich
Copy link

Adds an isLoaded property and load method to DS.RecordArray. The developer's implementation of adapter.findAll and adapter.findMany can now function similar to existing adapter.findQuery semantics. Once all the results from a specific findAll or findMany query are retrieved, the load method is called and an isLoaded flag is set to true on the corresponding DS.RecordArray or DS.ManyArray.

For example:

findMany: function (store, type, ids, query, manyArray) {
  var request = { }; // some request

  var success = function(data, textStatus, jqXHR) {
    manyArray.load(JSON.parse(data));
  };

  $.ajax({
    'url': 'rest.php',  
    'type': 'POST', 
    'data': JSON.stringify(request),
    'success': [success]
  });
}

or:

findAll: function (store, type, recordArray) {
  var request = { }; // some request

  var success = function(data, textStatus, jqXHR) {
    recordArray.load(JSON.parse(data));
  };

  $.ajax({
    'url': 'rest.php',  
    'type': 'POST', 
    'data': JSON.stringify(request),
    'success': [success]
  });
}

@josepjaume
Copy link

Just what I was looking for :). It's just weird that you can't know wether the collection is loaded using findAll but you do when using findQuery.

+1!

@wycats
Copy link
Member

wycats commented Jun 19, 2012

This is resolved by f707b6c.

findAll is actually a bit different from what you are thinking. In particular, it's a live query that reflects all current items for a particular type. I think we should modify findAll to kick off a query and populate an AdapterPopulatedModelArray, and create a new all that represents the live query.

I'm closing this ticket for now.

@wycats wycats closed this Jun 19, 2012
@tchak
Copy link
Member

tchak commented Jun 22, 2012

@wycats I made changes as you proposed
https://github.com/tchak/data/compare/all-findAll
It break's a lot of tests as we change the semantics of findAll. If you confirm that this is what you want I will clean it up and make a PR

@tchak
Copy link
Member

tchak commented Jun 22, 2012

PR : #301

@hjdivad
Copy link
Member

hjdivad commented Jul 10, 2012

@wycats why would you not want isLoaded (or an equivalent) on the live query? The live query has the semantics we want for new records, but we still want to know whether or not the initial load is done to prevent rendering a view with unloaded, or partially loaded, records.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants