PHP 7.4.33
Preview: notifyManager.ts Size: 2.36 KB
/var/www/gtechmarathon2026.bitkit.dk/httpdocs/node_modules/@tanstack/query-core/src/notifyManager.ts
// TYPES

type NotifyCallback = () => void

type NotifyFunction = (callback: () => void) => void

type BatchNotifyFunction = (callback: () => void) => void

type BatchCallsCallback<T extends Array<unknown>> = (...args: T) => void

type ScheduleFunction = (callback: () => void) => void

export const defaultScheduler: ScheduleFunction = (cb) => setTimeout(cb, 0)

export function createNotifyManager() {
  let queue: Array<NotifyCallback> = []
  let transactions = 0
  let notifyFn: NotifyFunction = (callback) => {
    callback()
  }
  let batchNotifyFn: BatchNotifyFunction = (callback: () => void) => {
    callback()
  }
  let scheduleFn = defaultScheduler

  const schedule = (callback: NotifyCallback): void => {
    if (transactions) {
      queue.push(callback)
    } else {
      scheduleFn(() => {
        notifyFn(callback)
      })
    }
  }
  const flush = (): void => {
    const originalQueue = queue
    queue = []
    if (originalQueue.length) {
      scheduleFn(() => {
        batchNotifyFn(() => {
          originalQueue.forEach((callback) => {
            notifyFn(callback)
          })
        })
      })
    }
  }

  return {
    batch: <T>(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: <T extends Array<unknown>>(
      callback: BatchCallsCallback<T>,
    ): BatchCallsCallback<T> => {
      return (...args) => {
        schedule(() => {
          callback(...args)
        })
      }
    },
    schedule,
    /**
     * 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
}

// SINGLETON
export const notifyManager = createNotifyManager()

Directory Contents

Dirs: 0 × Files: 22
Name Size Perms Modified Actions
2.06 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
8.08 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.52 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
5.27 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
4.69 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
8.98 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
6.86 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
4.76 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.36 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.77 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
7.54 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
18.48 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
5.55 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
16.36 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
22.87 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
851 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
5.50 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.71 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
557 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.87 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
38.76 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
11.10 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).