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

Ability to tell if the result of a findAll had any records from the adapter #83

Closed
pixelcort opened this issue Feb 9, 2012 · 14 comments
Labels
🏷️ feat This PR introduces a new feature

Comments

@pixelcort
Copy link

Currently DS.Store#findAll returns an instance of DS.ModelArray, which does not include an isLoaded property.

Instead, DS.Store#findAll should return something that includes an isLoaded property.

When the adapter returns all the data for the findAll, the isLoaded property on the originally returned result of DS.Store#findAll should change to true.

@pixelcort
Copy link
Author

Rationale is I want to be able to determine whether there are genuinely no instances of a model on the server vs just there not being any instances on the client yet.

@wycats
Copy link
Member

wycats commented Feb 26, 2012

Just to be clear on semantics, what you're saying is that as soon as a single item for a type was added to the store, all findAll queries for that type should switch to isLoaded?

@pixelcort
Copy link
Author

@wycats I'm okay with that, but the problem then is what happens if the server has no instances of that type?

My goal is to display a UI that says "There are no Cars", but I don't want to show this UI while any potential Cars are loading from the initial call to DS.Adapter#findAll.

@MikeAski
Copy link

MikeAski commented Mar 7, 2012

My 2 cents...

I also need some notification mecanism to perform some processing once the findAll has complete results loading.
Such a property would be observable, so processing could be triggered.

I may be wrong, but it seems to me this observation is quite "transient", and it is certainly useless to keep this observation after it has been triggered once.
In this case, what about a more simple "callback" mecanism, that would allow to perform processing once, after all (possible) data from server have been loaded?

@pixelcort Do my need meets yours?

@wycats Would it be ember-idiomatic to have such a callback mecanism?

@MikeAski
Copy link

MikeAski commented Mar 7, 2012

Just found a solution to my problem, which could also match your need, @pixelcort : http://stackoverflow.com/a/9568939/90741

@pixelcort
Copy link
Author

@MikeAndrzejewski that works but feels like Store#findQuery is a private method and that we should instead be using Store#find. Your workaround would probably also work with Store#filter with a function that always returns true, and that would guard against implementation detail changes inside of how findQuery works.

However, in any case, this doesn't resolve the issue, which is how do I determine whether the adapter returned no items for a given findAll query, or simply that it hasn't returned yet.

@pixelcort
Copy link
Author

Updated title to better reflect issue.

@MSch
Copy link

MSch commented Mar 15, 2012

Triggering a event once the ModelArray starts populating and once it has finished populating would cover my usecase perfectly.

@analytically
Copy link

+1 this is pretty annoying...

@mmpestorich
Copy link

Here's how I worked around this issue.

I created a new DS.Adapter and implemented findAll such that its success callback sets an isLoaded property to true on the DS.RecordArray that is returned and cached in the store.

findAll(store, type) {

    var request = { ... }

    var success = function(data, status, xhr) {
        data = JSON.parse(data);
        store.loadMany(type, data);
        store.typeMapFor(type).findAllCache.set('isLoaded', true);
    }

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

Seems to be working for me. I can now observe isLoaded on a findAll's return value.

@pixelcort
Copy link
Author

@mmpestorich nice workaround; I'll try using that next time. Thanks!

@mmpestorich
Copy link

I just posted Pull Request #271 that implements isLoaded on DS.RecordArray. With these changes, the resulting array from store.findAll and store.findMany can be used in similar fashion to that of store.findQuery. I've tested it every which way I can think of and it seems to do what I expect of it.

@wagenet
Copy link
Member

wagenet commented Jun 21, 2012

Looks like f707b6c addresses this.

@wagenet wagenet closed this as completed Jun 21, 2012
@mmpestorich
Copy link

It does. Thanks.

@runspired runspired added 🏷️ feat This PR introduces a new feature and removed Improvement labels Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ feat This PR introduces a new feature
Projects
None yet
Development

No branches or pull requests

8 participants