Skip to content
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

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

stereosteve
Copy link

🎯 Changes

Adds an option to httpBatchLink to configure a batchInterval 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

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

@stereosteve stereosteve requested a review from a team as a code owner February 12, 2024 16:02
Copy link

vercel bot commented Feb 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
trpc-next-app-dir ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2024 4:05pm
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2024 4:05pm

Copy link

vercel bot commented Feb 12, 2024

@stereosteve is attempting to deploy a commit to the trpc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Member

@juliusmarminge juliusmarminge left a 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?

Copy link
Member

@KATT KATT left a 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

@@ -39,6 +39,7 @@ const throwFatalError = () => {
*/
export function dataLoader<TKey, TValue>(
batchLoader: BatchLoader<TKey, TValue>,
batchInterval = 0,
Copy link
Member

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

Suggested change
batchInterval = 0,
opts: {
/**
* .......... docs
*/
batchInterval?: number;
} = {},

Comment on lines 7 to +9
HTTPLinkBaseOptions<TRoot> & {
maxURLLength?: number;
batchInterval?: number;
Copy link
Member

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
opts.batchInterval,
opts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants