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

Method addObserver

packages/query-core/src/mutation.ts:197–210  ·  view source on GitHub ↗

* Subscribes an observer to the mutation and stops its garbage collection. * @internal * @param observer - The observer to add. Adding an observer that is already subscribed does * nothing.

(observer: MutationObserver<any, any, any, any>)

Source from the content-addressed store, hash-verified

195 * nothing.
196 */
197 addObserver(observer: MutationObserver<any, any, any, any>): void {
198 if (!this.#observers.includes(observer)) {
199 this.#observers.push(observer)
200
201 // Stop the mutation from being garbage collected
202 this.clearGcTimeout()
203
204 this.#mutationCache.notify({
205 type: 'observerAdded',
206 mutation: this,
207 observer,
208 })
209 }
210 }
211
212 /**
213 * Unsubscribes an observer from the mutation.

Callers

nothing calls this directly

Calls 1

notifyMethod · 0.45

Tested by

no test coverage detected