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

Method addObserver

packages/query-core/src/query.ts:618–627  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

616 * nothing.
617 */
618 addObserver(observer: QueryObserver<any, any, any, any, any>): void {
619 if (!this.observers.includes(observer)) {
620 this.observers.push(observer)
621
622 // Stop the query from being garbage collected
623 this.clearGcTimeout()
624
625 this.#cache.notify({ type: 'observerAdded', query: this, observer })
626 }
627 }
628
629 /**
630 * Unsubscribes an observer from the query.

Callers 7

Devtools.test.tsxFile · 0.45
onSubscribeMethod · 0.45
#updateQueryMethod · 0.45
onSubscribeMethod · 0.45
mutateMethod · 0.45
mutation.test.tsxFile · 0.45
query.test.tsxFile · 0.45

Calls 1

notifyMethod · 0.45

Tested by

no test coverage detected