falcor-path-utils
falcor-path-utils copied to clipboard
Enhancement: collapse indices to range
Collapse correctly collapses indices into a range when all indices are w/i that range. E.g.
collapse([
['key1', [1,2,3,4,5], 'key2']
])
// > [['key1', { from: 1, to: 5 }, 'key2']]
However, it doesn't collapse indices to a range when there are additional indices outside of that range. E.g.
collapse([
['key1', [1,2,3,4,5,10], 'key2']
])
// > [['key1', [1,2,3,4,5,10], 'key2']]
Hey @jameslaneconkling - I believe that's currently by design. That is, we only attempt to collapse ranges when all numerical keys are contiguous. cc @jhusain @lrowe
@sdesai is it a desirable enhancement? If so, I could look at a possible implementation.
The use case I'm running into often.
- I request a range of resources, e.g.
['items', { to: 20 }, 'name']
- One of those items is already in the cache, e.g.
{ items: { 4: { name: 'item 4' } } }
- The resulting request to the router is for
['items', [0, 1, 2, 3, 5, 6, 7, ..., 20], 'name']
, rather than['items', [{ to: 3 }, { from: 5, to: 20 }], 'name']
Hey @jameslaneconkling : The use case definitively makes sense. I'll let @jhusain or @lrowe comment on whether it's worth going after for the over-the-wire savings, and corresponding run-time trade-offs - I imagine it's something we've considered/discussed at some point and @jhusain may have that context.