diff --git a/jest.setup.js b/jest.setup.js index c9995e4447..d8831bc4bb 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -1,8 +1,8 @@ import { act } from '@testing-library/react' -import { setUpdateFn } from './src' +import { setNotifyFn } from './src' -// Wrap updates with act to make sure React knows about React Query updates -setUpdateFn(fn => { +// Wrap notifications with act to make sure React knows about React Query updates +setNotifyFn(fn => { act(fn) }) diff --git a/src/core/index.ts b/src/core/index.ts index e9819c744e..a5af8b966c 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -1,6 +1,6 @@ export { QueryCache } from './queryCache' export { QueryClient } from './queryClient' -export { setBatchUpdatesFn, setUpdateFn } from './notifyManager' +export { setBatchNotifyFn, setNotifyFn } from './notifyManager' export { setLogger } from './logger' export { setFocusHandler } from './focusHandler' export { setOnlineHandler } from './onlineHandler' diff --git a/src/core/notifyManager.ts b/src/core/notifyManager.ts index 7f6d319eee..b0ffad1698 100644 --- a/src/core/notifyManager.ts +++ b/src/core/notifyManager.ts @@ -4,36 +4,36 @@ import { scheduleMicrotask } from './utils' type NotifyCallback = () => void -type UpdateFunction = (callback: () => void) => void +type NotifyFunction = (callback: () => void) => void -type BatchUpdatesFunction = (callback: () => void) => void +type BatchNotifyFunction = (callback: () => void) => void // GETTERS AND SETTERS -// Default to a dummy "update" implementation that just runs the callback -let updateFn: UpdateFunction = (callback: () => void) => { +// Default to a dummy "notify" implementation that just runs the callback +let notifyFn: NotifyFunction = (callback: () => void) => { callback() } -// Default to a dummy "batch update" implementation that just runs the callback -let batchUpdatesFn: BatchUpdatesFunction = (callback: () => void) => { +// Default to a dummy "batch notify" implementation that just runs the callback +let batchNotifyFn: BatchNotifyFunction = (callback: () => void) => { callback() } /** - * Use this function to set a custom update function. - * This can be used to for example wrap updates with `React.act` while running tests. + * Use this function to set a custom notify function. + * This can be used to for example wrap notifications with `React.act` while running tests. */ -export function setUpdateFn(fn: UpdateFunction) { - updateFn = fn +export function setNotifyFn(fn: NotifyFunction) { + notifyFn = fn } /** - * Use this function to set a custom batch function to batch updates together into a single render pass. + * Use this function to set a custom function to batch notifications together into a single tick. * By default React Query will use the batch function provided by ReactDOM or React Native. */ -export function setBatchUpdatesFn(fn: BatchUpdatesFunction) { - batchUpdatesFn = fn +export function setBatchNotifyFn(fn: BatchNotifyFunction) { + batchNotifyFn = fn } // CLASS @@ -57,12 +57,12 @@ class NotifyManager { return result } - schedule(notify: NotifyCallback): void { + schedule(callback: NotifyCallback): void { if (this.transactions) { - this.queue.push(notify) + this.queue.push(callback) } else { scheduleMicrotask(() => { - updateFn(notify) + notifyFn(callback) }) } } @@ -72,9 +72,9 @@ class NotifyManager { this.queue = [] if (queue.length) { scheduleMicrotask(() => { - batchUpdatesFn(() => { - queue.forEach(notify => { - updateFn(notify) + batchNotifyFn(() => { + queue.forEach(callback => { + notifyFn(callback) }) }) }) diff --git a/src/react/setBatchUpdatesFn.ts b/src/react/setBatchUpdatesFn.ts index 5b68ad371b..32d3df1c20 100644 --- a/src/react/setBatchUpdatesFn.ts +++ b/src/react/setBatchUpdatesFn.ts @@ -1,4 +1,4 @@ -import { setBatchUpdatesFn } from '../core' +import { setBatchNotifyFn } from '../core' import { unstable_batchedUpdates } from './reactBatchedUpdates' -setBatchUpdatesFn(unstable_batchedUpdates) +setBatchNotifyFn(unstable_batchedUpdates)