MCPcopy
hub / github.com/TanStack/query / updateResult

Method updateResult

packages/query-core/src/queryObserver.ts:644–700  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

642 }
643
644 updateResult(): void {
645 const prevResult = this.#currentResult as
646 | QueryObserverResult<TData, TError>
647 | undefined
648
649 const nextResult = this.createResult(this.#currentQuery, this.options)
650
651 this.#currentResultState = this.#currentQuery.state
652 this.#currentResultOptions = this.options
653
654 if (this.#currentResultState.data !== undefined) {
655 this.#lastQueryWithDefinedData = this.#currentQuery
656 }
657
658 // Only notify and update result if something has changed
659 if (shallowEqualObjects(nextResult, prevResult)) {
660 return
661 }
662
663 this.#currentResult = nextResult
664
665 const shouldNotifyListeners = (): boolean => {
666 if (!prevResult) {
667 return true
668 }
669
670 const { notifyOnChangeProps } = this.options
671 const notifyOnChangePropsValue =
672 typeof notifyOnChangeProps === 'function'
673 ? notifyOnChangeProps()
674 : notifyOnChangeProps
675
676 if (
677 notifyOnChangePropsValue === 'all' ||
678 (!notifyOnChangePropsValue && !this.#trackedProps.size)
679 ) {
680 return true
681 }
682
683 const includedProps = new Set(
684 notifyOnChangePropsValue ?? this.#trackedProps,
685 )
686
687 if (this.options.throwOnError) {
688 includedProps.add('error')
689 }
690
691 return Object.keys(this.#currentResult).some((key) => {
692 const typedKey = key as keyof QueryObserverResult
693 const changed = this.#currentResult[typedKey] !== prevResult[typedKey]
694
695 return changed && includedProps.has(typedKey)
696 })
697 }
698
699 this.#notify({ listeners: shouldNotifyListeners() })
700 }
701

Callers 8

onSubscribeMethod · 0.95
setOptionsMethod · 0.95
fetchMethod · 0.95
#updateStaleTimeoutMethod · 0.95
onQueryUpdateMethod · 0.95
useBaseQueryFunction · 0.80
createBaseQueryFunction · 0.80
useBaseQueryFunction · 0.80

Calls 3

createResultMethod · 0.95
#notifyMethod · 0.95
shallowEqualObjectsFunction · 0.90

Tested by

no test coverage detected