New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce Infinite Query Support #4249
Conversation
…uerying will happen
…of args and forward/backwards direction
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
✅ Deploy Preview for redux-starter-kit-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Interesting! Is there a particular reason you went for The more this API would look like |
Ah, actually just a mistake in my examples! I was trying to represent that the "query" part of the new definition runs using the standard query initiate/thunk. My intention is to have it act very very similarly to the
And then the list will become much bigger once we start addressing the options :D |
…files Update example lockfiles
Update `actions/checkout` usages to v4
…o update-ci-actions
…Page functions + Thunk
I updated the top comment as an overview as well, but I'll leave a timeline comment too for better visibility/discussion purposes. @phryneas Would it be more likely that the query/queryFn would have access to all the normal extraOptions that a Changes and Current process:
refetch: () =>
dispatch(
infiniteQueryAction(arg, { subscribe: false, forceRefetch: true })
),
fetchNextPage: () =>
dispatch(
infiniteQueryAction(arg, { subscribe: false, forceRefetch: true, direction: "forward"})
),
fetchPreviousPage: () =>
dispatch(
infiniteQueryAction(arg, {subscribe: false, forceRefetch: true, direction: "backwards"})
),
const thunk = infiniteQueryThunk({
type: 'query',
...
queryCacheKey,
data,
param,
previous,
direction
})
if (arg.direction && arg.data.pages.length) {
const previous = arg.direction === 'backwards'
const pageParamFn = previous ? getPreviousPageParam : getNextPageParam
const oldData = arg.data
const param = pageParamFn(arg.infiniteQueryOptions, oldData)
result = await fetchPage(oldData, param, previous)
} else {
// Fetch first page
result = await fetchPage(
{ pages: [], pageParams: [] },
oldPageParams[0] ?? arg.originalArgs,
)
//original
// const remainingPages = pages ?? oldPages.length
const remainingPages = oldPages.length
// Fetch remaining pages
for (let i = 1; i < remainingPages; i++) {
const param = getNextPageParam(arg.infiniteQueryOptions, result.data as InfiniteData<unknown>)
result = await fetchPage(result.data as InfiniteData<unknown>, param)
}
} Notes/Considerations
|
Co-authored-by: Ben Durrant <ben.j.durrant@gmail.com>
…-typing-for-use-query correction of the refetch function type in useQuery documentation
Fix some docs regarding enhancer configuration
…o update-ci-actions
…uerying will happen
…of args and forward/backwards direction
…Page functions + Thunk
…finiteQueryDefinition # Conflicts: # packages/toolkit/src/query/core/buildInitiate.ts # packages/toolkit/src/query/core/buildSlice.ts # packages/toolkit/src/query/core/buildThunks.ts # packages/toolkit/src/query/core/module.ts # packages/toolkit/src/query/createApi.ts # packages/toolkit/src/query/endpointDefinitions.ts
This PR aims to introduce the InfiniteQuery to RTKQ. My current strategy is to basically follow Lenz's suggestion in the RTKQ Infinite Query thread.
This PR is a starting point for discussion. Feedback is welcome on the overall approach and implementation details. Its current state is just my initial method of adding the new endpoint definition and I am currently working out the best way to turn the infiniteQuery
initiate
into something that can fetch multiple args from selection.This new definition allows for the following:
selection Function: Handles the core logic of fetching data in an infinite fashion, determining when to make subsequent requests.nestedQuery Option: Provides the ability to integrate dependent queries that retrieve additional details for each chunk of data.Example Usage:
Open Questions
Is there any query logic/options that we would NOT want to be accessible by the infiniteQuery? Or should I default to no access to additional options i.e. subscription
Code Changes
Draft Status: This PR is a starting point for discussion. Feedback is welcome on the overall approach and implementation details.