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

Method removeObserver

packages/query-core/src/query.ts:362–382  ·  view source on GitHub ↗
(observer: QueryObserver<any, any, any, any, any>)

Source from the content-addressed store, hash-verified

360 }
361
362 removeObserver(observer: QueryObserver<any, any, any, any, any>): void {
363 if (this.observers.includes(observer)) {
364 this.observers = this.observers.filter((x) => x !== observer)
365
366 if (!this.observers.length) {
367 // If the transport layer does not support cancellation
368 // we'll let the query continue so the result can be cached
369 if (this.#retryer) {
370 if (this.#abortSignalConsumed || this.#isInitialPausedFetch()) {
371 this.#retryer.cancel({ revert: true })
372 } else {
373 this.#retryer.cancelRetry()
374 }
375 }
376
377 this.scheduleGc()
378 }
379
380 this.#cache.notify({ type: 'observerRemoved', query: this, observer })
381 }
382 }
383
384 getObserversCount(): number {
385 return this.observers.length

Callers 6

destroyMethod · 0.45
#updateQueryMethod · 0.45
onUnsubscribeMethod · 0.45
resetMethod · 0.45
mutateMethod · 0.45
query.test.tsxFile · 0.45

Calls 3

#isInitialPausedFetchMethod · 0.95
cancelMethod · 0.80
notifyMethod · 0.45

Tested by

no test coverage detected