MCPcopy Create free account
hub / github.com/TanStack/query / register

Function register

packages/query-devtools/src/createCacheSubscriptionRegistry.ts:25–39  ·  view source on GitHub ↗

* Registers a subscription that is removed when the current owner is cleaned up. * @param callback - Computes the value from the cache. * @param setter - Receives the computed value on every update. * @param shouldUpdate - Decides whether an event updates this subscription. Defaults to ever

(
    callback: (
      cache: Accessor<TCache>,
      // oxlint-disable-next-line typescript/no-unsafe-function-type -- matches the 'Exclude<T, Function>' that Solid's 'Setter' accepts
    ) => Exclude<T, Function>,
    setter: Setter<T>,
    shouldUpdate: (event: TEvent) => boolean = () => true,
  )

Source from the content-addressed store, hash-verified

23 * event.
24 */
25 function register<T>(
26 callback: (
27 cache: Accessor<TCache>,
28 // oxlint-disable-next-line typescript/no-unsafe-function-type -- matches the 'Exclude<T, Function>' that Solid's 'Setter' accepts
29 ) => Exclude<T, Function>,
30 setter: Setter<T>,
31 shouldUpdate: (event: TEvent) => boolean = () => true,
32 ) {
33 const id = Symbol()
34 subscriptions.set(id, {
35 shouldUpdate,
36 update: (cache) => setter(callback(cache)),
37 })
38 onCleanup(() => subscriptions.delete(id))
39 }
40
41 /**
42 * Updates every subscription whose `shouldUpdate` accepts the event.

Callers

nothing calls this directly

Calls 1

callbackFunction · 0.85

Tested by

no test coverage detected