Git Product home page Git Product logo

Comments (3)

ludovicthomas avatar ludovicthomas commented on June 30, 2024

On our side, to avoid adding some cache logic, we have added the object attributes to the allTodos route, so a single call is done to get refs and properties. We use shared methods between allTodos and todosById routes to ensure consistency between attributes returned.

Here is a sample in your case:

{
  route: 'allTodos[{ranges:indices}][{keys:attrs}]',
  get({ indices, attrs }) {
     ... return $ref and prop of todosById...
  }
}

For the length route, we have a separate route in our API, so there is no need for optimization on this one on our side.

Would be happy to have some feedback of other Falcor devs too.

from falcor-router.

jmerrifield avatar jmerrifield commented on June 30, 2024

Thanks @ludovicthomas, that's really interesting! I think I prefer your approach - just so I'm clear, is your allTodos route returning the following?

// Assuming we asked for allTodos[0]['name']
[
  // $ref to todosById
  { path: ['allTodos', 0], value: $ref(['todosById', 100]) },

  // values _under the todosById path_
  { path: ['todosById', 100, 'name'], value: $atom('get milk') }
]

from falcor-router.

ludovicthomas avatar ludovicthomas commented on June 30, 2024

Sorry for the late reply.

Yes that's exactly that, in fact we have helpers that we use on both routes todosById and todos to return the properties of todosById. It's called todoToPathValues in the following example

Something like this for route todos:

// Get data from service call, then construct paths
const properties = pathSet.attrs;
let pathValues = _.map(pathSet.indices, (indice, index) => {
    const todo = data[index];
    let results = { path: ['todos', indice], value: $ref(['todosById', todo.id])};
    results.push.apply(results, todoToPathValues(todo, properties));
    return results;
});
return _.flatten(pathValues);

and something like this for the route todoById:

// Get data from service call, then construct paths
const properties = pathSet.attrs;
let pathValues = _.map(pathSet.todoIds, (id, index) => {
    return todoToPathValues(data[index], properties);
});
return _.flatten(pathValues);

With the todoToPathValues something like:

function todoToPathValues(todo, properties) {
    let results = [];
    properties.forEach((key) => {
        results.push({
            path: ['todoById', todo.id, key],
            value: _.get(todo, key, $atom(null))
        });
    });
    return results;
}

from falcor-router.

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.