requirements
the fetch function of a Query is called with a single argument: an object containing all the needed params + other queries to perform the async call to the API.
This is not enough for paginated APIs as, for those, we would need to receive as input of fetch the previous result as well.
This is the use case I'm imagining:
- API to get a feed of posts
- Fe client that shows the feed and, when you scroll to the bottom, loads more
Right now, we could:
- reload every rendered post + load more post every time the user scrolls (bad perfs)
- store the previous value in a component + load only the new posts + concat the new data to the previous one inside the component (probably in
componentWillReceiveProps) and render the posts using the component's this.state
- add a global state param "prevValue" + keep it in sync in the component (probably in
componentWillReceiveProps) + move the concat logic in the query
What I want:
- Move the concat logic inside the query
- no state in the UI Component
- no
prevValue variable in the global state
The container should be rendered with the correct values and the query should ask the API only for the posts that haven't been previously downloaded
specs
An option could be to pass the value stored in the cache (previous value) as second argument of fetch.
One problem I see with this is that the previous value is only useful for paginated API+UI.
Maybe we could make it "more difficult" for the user to use the previous value by adding another class called PaginatedQuery that looks the same as Query but passes a second argument to fetch (this is only needed to discourage the user to use the cached value when it's not needed, or worse, risky)
misc
{optional: other useful info}