From a17184d97085c8b752dbf3278d6bdf3f78463c52 Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Mon, 9 Sep 2024 02:23:13 +0900 Subject: [PATCH 1/2] fix(query-core): jsdoc of notifyManager --- packages/query-core/src/notifyManager.ts | 94 +++++++++++------------- 1 file changed, 42 insertions(+), 52 deletions(-) diff --git a/packages/query-core/src/notifyManager.ts b/packages/query-core/src/notifyManager.ts index ad80a84726..2cd671b6e3 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) @@ -49,19 +31,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 +45,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 } From d2f9210e74e531fbd93447a8749e37b86cd43509 Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Mon, 9 Sep 2024 02:33:03 +0900 Subject: [PATCH 2/2] chore: update --- packages/query-core/src/notifyManager.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/query-core/src/notifyManager.ts b/packages/query-core/src/notifyManager.ts index 2cd671b6e3..3315c61646 100644 --- a/packages/query-core/src/notifyManager.ts +++ b/packages/query-core/src/notifyManager.ts @@ -30,7 +30,6 @@ export function createNotifyManager() { }) } } - const flush = (): void => { const originalQueue = queue queue = []