Comments (3)
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.
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.
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)
- Long key strings being coerced to unsafe numbers HOT 5
- Ability to auto-generate docunentation HOT 8
- [Discussion]: Strategies for modular, testable routes
- Exceptions in the router are not treated as the same for get/set/call
- "route: ['foo', 'bar', '{integers}']" doesn't match but "route: 'foo.bar[{integers}]'" does?!? HOT 2
- Why materialize? HOT 10
- Repo activity HOT 9
- Invalidation of graph value via jsonGraphEnvelope isn't returned to client HOT 2
- In v0.4.0+, values of type undefined work differently - update documentation
- Build regression updating to 0.5.0 HOT 7
- Cannot find module `symbol-observable`
- Correct way to return path item not found?
- How to handle creating multiple resources, but one of them has a validation error.
- Curl methods to get data from falcor servers
- Router fails to complete all routes for path set containing array in root node HOT 1
- in route handler, buffer synchronous observable emissions
- mergeCacheAndGatherRefsAndInvalidations causing unnecessary slowdown
- .travis.yml: The 'sudo' tag is now deprecated in Travis CI
- Returning ref from route results in incomplete response
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from falcor-router.