Skip to content
0

katanakit-js / notifyManager

Variable: notifyManager ​

ts
const notifyManager: {
  batch: <T>(callback) => T;
  batchCalls: <T>(callback) => BatchCallsCallback<T>;
  schedule: (callback) => void;
  setBatchNotifyFunction: (fn) => void;
  setNotifyFunction: (fn) => void;
  setScheduler: (fn) => void;
};

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/notifyManager.d.ts:71

Handles scheduling and batching callbacks in TanStack Query.

Type Declaration ​

batch ​

ts
readonly batch: <T>(callback) => T;

Batches all updates scheduled inside the passed callback. This is mainly used internally to optimize query client updating. Batches can be nested; the queue is only flushed once the outermost batch call finishes. The return value of callback is passed through.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterType
callback() => T

Returns ​

T

batchCalls ​

ts
readonly batchCalls: <T>(callback) => BatchCallsCallback<T>;

All calls to the wrapped function will be batched.

Type Parameters ​

Type Parameter
T extends unknown[]

Parameters ​

ParameterType
callbackBatchCallsCallback<T>

Returns ​

BatchCallsCallback<T>

schedule ​

ts
readonly schedule: (callback) => void;

Schedules a function to be run on the next batch. By default, the batch is run with a setTimeout, but this can be configured via setScheduler.

Parameters ​

ParameterType
callbackNotifyCallback

Returns ​

void

setBatchNotifyFunction ​

ts
readonly setBatchNotifyFunction: (fn) => void;

Use this method to set a custom function to batch notifications together into a single tick. Framework adapters use this to plug in their own batching primitive, so that a single query update only triggers one re-render instead of one per subscriber.

Parameters ​

ParameterType
fnBatchNotifyFunction

Returns ​

void

Example ​

ts
import { notifyManager } from '@tanstack/query-core'
import { batch } from 'solid-js'

notifyManager.setBatchNotifyFunction(batch)

setNotifyFunction ​

ts
readonly setNotifyFunction: (fn) => void;

Use this method to set a custom notify function. This can be used to for example wrap notifications with React.act while running tests.

Parameters ​

ParameterType
fnNotifyFunction

Returns ​

void

setScheduler ​

ts
readonly setScheduler: (fn) => void;

Configures a custom callback that schedules when the next batch runs. The default behavior is setTimeout(callback, 0).

Parameters ​

ParameterType
fnScheduleFunction

Returns ​

void

Example ​

ts
import { notifyManager } from '@tanstack/query-core'

// Schedule batches in the next microtask
notifyManager.setScheduler(queueMicrotask)

// Schedule batches before the next frame is rendered
notifyManager.setScheduler(requestAnimationFrame)

// Schedule batches some time in the future
notifyManager.setScheduler((cb) => setTimeout(cb, 10))

Released under the MIT License.