diff --git a/packages/query-core/src/notifyManager.ts b/packages/query-core/src/notifyManager.ts index ad80a84726..3315c61646 100644 --- a/packages/query-core/src/notifyManager.ts +++ b/packages/query-core/src/notifyManager.ts @@ -21,24 +21,6 @@ export function createNotifyManager() { } let scheduleFn: ScheduleFunction = (cb) => setTimeout(cb, 0) - const setScheduler = (fn: ScheduleFunction) => { - scheduleFn = fn - } - - const batch = (callback: () => T): T => { - let result - transactions++ - try { - result = callback() - } finally { - transactions-- - if (!transactions) { - flush() - } - } - return result - } - const schedule = (callback: NotifyCallback): void => { if (transactions) { queue.push(callback) @@ -48,20 +30,6 @@ export function createNotifyManager() { }) } } - - /** - * All calls to the wrapped function will be batched. - */ - const batchCalls = >( - callback: BatchCallsCallback, - ): BatchCallsCallback => { - return (...args) => { - schedule(() => { - callback(...args) - }) - } - } - const flush = (): void => { const originalQueue = queue queue = [] @@ -76,29 +44,50 @@ export function createNotifyManager() { } } - /** - * Use this method to set a custom notify function. - * This can be used to for example wrap notifications with `React.act` while running tests. - */ - const setNotifyFunction = (fn: NotifyFunction) => { - notifyFn = fn - } - - /** - * Use this method 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. - */ - const setBatchNotifyFunction = (fn: BatchNotifyFunction) => { - batchNotifyFn = fn - } - return { - batch, - batchCalls, + batch: (callback: () => T): T => { + let result + transactions++ + try { + result = callback() + } finally { + transactions-- + if (!transactions) { + flush() + } + } + return result + }, + /** + * All calls to the wrapped function will be batched. + */ + batchCalls: >( + callback: BatchCallsCallback, + ): BatchCallsCallback => { + return (...args) => { + schedule(() => { + callback(...args) + }) + } + }, schedule, - setNotifyFunction, - setBatchNotifyFunction, - setScheduler, + /** + * Use this method to set a custom notify function. + * This can be used to for example wrap notifications with `React.act` while running tests. + */ + setNotifyFunction: (fn: NotifyFunction) => { + notifyFn = fn + }, + /** + * Use this method 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. + */ + setBatchNotifyFunction: (fn: BatchNotifyFunction) => { + batchNotifyFn = fn + }, + setScheduler: (fn: ScheduleFunction) => { + scheduleFn = fn + }, } as const }