Git Product home page Git Product logo

Comments (14)

pixelcort avatar pixelcort commented on May 19, 2024

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.

from data.

wycats avatar wycats commented on May 19, 2024

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?

from data.

pixelcort avatar pixelcort commented on May 19, 2024

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

from data.

MikeAski avatar MikeAski commented on May 19, 2024

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?

from data.

MikeAski avatar MikeAski commented on May 19, 2024

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

from data.

pixelcort avatar pixelcort commented on May 19, 2024

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

from data.

pixelcort avatar pixelcort commented on May 19, 2024

Updated title to better reflect issue.

from data.

MSch avatar MSch commented on May 19, 2024

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

from data.

analytically avatar analytically commented on May 19, 2024

+1 this is pretty annoying...

from data.

mmpestorich avatar mmpestorich commented on May 19, 2024

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.

from data.

pixelcort avatar pixelcort commented on May 19, 2024

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

from data.

mmpestorich avatar mmpestorich commented on May 19, 2024

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.

from data.

wagenet avatar wagenet commented on May 19, 2024

Looks like f707b6c addresses this.

from data.

mmpestorich avatar mmpestorich commented on May 19, 2024

It does. Thanks.

from data.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.