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

Method removeObserver

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

@internal

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

Source from the content-addressed store, hash-verified

521
522 /** @internal */
523 removeObserver(observer: QueryObserver<any, any, any, any, any>): void {
524 const index = this.observers.indexOf(observer)
525 if (index !== -1) {
526 this.observers.splice(index, 1)
527
528 if (!this.observers.length) {
529 // If the transport layer does not support cancellation
530 // we'll let the query continue so the result can be cached
531 if (this.#retryer) {
532 if (
533 this.#abortSignalConsumed ||
534 (this.state.fetchStatus === 'paused' &&
535 this.state.status === 'pending')
536 ) {
537 this.#retryer.cancel({ revert: true })
538 } else {
539 this.#retryer.cancelRetry()
540 }
541 }
542
543 this.scheduleGc()
544 }
545
546 this.#cache.notify({ type: 'observerRemoved', query: this, observer })
547 }
548 }
549
550 /**
551 * Returns the number of observers currently subscribed to this query.

Callers 6

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

Calls 2

cancelMethod · 0.80
notifyMethod · 0.45

Tested by

no test coverage detected