feat(notifyManager): batch method configuration #6600
MergedNathanHuisman(GitHub profile, opens in a new tab)merged 19 commits into
main fromrefs/pull/6600/headmerged by TkDodo View on GitHubNathanHuisman(GitHub profile, opens in a new tab) changed the title
TkDodo reviewed
docs/react/reference/notifyManager.md line 84OutdatedResolvedby NathanHuisman(GitHub profile, opens in a new tab)@@ -0,0 +64,21 @@64+`setBatchNotifyFunction` sets the function to use for batched updates65+66+If your framework supports a custom batching function, you can let TanStack Query know about it by calling notifyManager.setBatchNotifyFunction.67+68+For example, this is how the batch function is set in solid-query:69+70+```ts71+import { notifyManager } from '@tanstack/query-core'72+import { batch } from 'solid-js'73+74+notifyManager.setBatchNotifyFunction(batch)75+```76+77+## `notifyManager.setBatchMethod`78+79+Sets the method for batching. There are four methods:80+81+`{ type: 'timer', timeout?: number }`:82+ The default is to use setTimeout with a timeout of 0. This has the effect of83+ scheduling a javascript task in the event loop some time later.84+`{ type: 'raf' }`: This batches all updates in a requestAnimationFrame, so@@ -1055,3 +1055,4 @@10551055 specifier: ^2.8.010561056 version: 2.8.0(solid-js@1.8.7)(vite@5.0.10)105710571058+ examples/solid/bug-test:TkDodo reviewed
packages/query-core/src/notifyManager.ts lines 26 to 38OutdatedResolvedby NathanHuisman(GitHub profile, opens in a new tab)@@ -19,3 +21,18 @@1921 let batchNotifyFn: BatchNotifyFunction = (callback: () => void) => {2022 callback()2123 }24+ let scheduleFn: ScheduleFunction25+26+ const setBatchMethod = (method: BatchMethod) => {27+ if (method.type === "tick") {28+ scheduleFn = queueMicrotask29+ } else if (method.type === "raf") {30+ scheduleFn = requestAnimationFrame31+ } else if (method.type === "timer") {32+ scheduleFn = (cb) => setTimeout(cb, method.timeout ?? 0)33+ // Disable because condition is necessary for typescript to detect method.fn34+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition35+ } else if (method.type === "custom") {36+ scheduleFn = method.fn37+ }38+ }- packages/query-core/src/notifyManager.ts line 26OutdatedResolvedby NathanHuisman(GitHub profile, opens in a new tab)@@ -19,3 +21,6 @@1921 let batchNotifyFn: BatchNotifyFunction = (callback: () => void) => {2022 callback()2123 }24+ let scheduleFn: ScheduleFunction25+26+ const setBatchMethod = (method: BatchMethod) => {
TkDodo approved these changes
TkDodo merged this3265ec3
TkDodo closed this
Sign in to join this conversation.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment