GithubHelp home page GithubHelp logo

Lazy loading relationships about orbit HOT 4 CLOSED

orbitjs avatar orbitjs commented on September 27, 2024
Lazy loading relationships

from orbit.

Comments (4)

dgeb avatar dgeb commented on September 27, 2024

@opsb You are correct that relationships are synchronously populated from the source. However, it's possible to asynchronously fetch them, as described in the README:

A model's relationships can be re-queried by calling reload() on a relationship object. This triggers the associated findLink call and returns its promise. Related records will be updated through transformations to the underlying source. Any changes should be reflected by the time the promise resolves.

For example:

planet.get('moons').reload().then(function() {
  console.log(planet.get('moons.length'));
});

Please re-open if you have any problems.

from orbit.

opsb avatar opsb commented on September 27, 2024

I did see that, if a view is showing a nested object graph though it's a bit cumbersome to have to go through the graph and call reload() on each relationship. In my case I'm now solving it by adding firebase listeners to each relationship when a record is loaded. That way they're loaded immediately and keep up to date with server side changes. This works fine for me but I think lazily loaded relationships would be worth addressing at some point, in particular with the JSON-API adapter.

from orbit.

dgeb avatar dgeb commented on September 27, 2024

Eager fetching is something that needs to be carefully controlled or else it will get out of control. However, I can imagine it can be controlled given the right configuration settings.

One scenario I could imagine is providing hooks to specify different include params in the JSONAPISource, depending on the type requested. Furthermore, we could extend schemas in orbit to allow per-source configuration data to be stored for each type. And that configuration data could flow from model definitions in ember-orbit.

from orbit.

opsb avatar opsb commented on September 27, 2024

Firebase makes great claims about being very efficient with regards to adding a large number of listeners, I'm building the Source based on this assumption initially but I'll see how it runs with my app and make it more intelligent if necessary.

With regards to specifying include params on a per type basis, I'd say that one of the major issues I had with ember-data is that it's not possible to specify includes on a per-scenario basis. I found this an extremely difficult juggling act as it meant loading up lots of unnecessary information when showing list views for instance. Bearing that in mind and considering that relationships are implemented as proxies it might be nice to allow something like:

persons.projects.includes(['members']);

I've had rails like scopes for relationships in the back of my mind for a while now, it's something that I'll take a look at when I've got some time.

from orbit.

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.