-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add batchInterval option to dataLoader #5474
base: next
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@stereosteve is attempting to deploy a commit to the trpc Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, mind adding a test and perhaps a sentence in the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder what the desired behavior should be when triggering another fetch while one is pending - should we further debounce it? That's what we did in #914
- Needs JSDoc about the option
- Should be an options object
- Needs docs in https://trpc.io/docs/client/links/httpBatchLin
@@ -39,6 +39,7 @@ const throwFatalError = () => { | |||
*/ | |||
export function dataLoader<TKey, TValue>( | |||
batchLoader: BatchLoader<TKey, TValue>, | |||
batchInterval = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this an options object instead
batchInterval = 0, | |
opts: { | |
/** | |
* .......... docs | |
*/ | |
batchInterval?: number; | |
} = {}, |
HTTPLinkBaseOptions<TRoot> & { | ||
maxURLLength?: number; | ||
batchInterval?: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be
HTTPLinkBaseOptions<TRoot> & DataLoaderOptions & { maxURLLength?: '..' }
that way, it inherits whatever docs and options we add on dataloader
const query = dataLoader<Operation, HTTPResult>(batchLoader('query')); | ||
const query = dataLoader<Operation, HTTPResult>( | ||
batchLoader('query'), | ||
opts.batchInterval, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opts.batchInterval, | |
opts |
🎯 Changes
Adds an option to
httpBatchLink
to configure abatchInterval
in milliseconds.This is an option that exists in dataloader and can be helpful if rendering of items in a list is spread out across multiple event loop ticks.
✅ Checklist