Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Add API to allows handling of paginated (infinite scroll) queries inside the Query itself #143

@FrancescoCioria

Description

@FrancescoCioria

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:

  1. API to get a feed of posts
  2. Fe client that shows the feed and, when you scroll to the bottom, loads more

Right now, we could:

  1. reload every rendered post + load more post every time the user scrolls (bad perfs)
  2. 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
  3. 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:

  1. Move the concat logic inside the query
  2. no state in the UI Component
  3. 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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions