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

Method updateResult

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

Source from the content-addressed store, hash-verified

622 }
623
624 updateResult(): void {
625 const prevResult = this.#currentResult as
626 | QueryObserverResult<TData, TError>
627 | undefined
628
629 const nextResult = this.createResult(this.#currentQuery, this.options)
630
631 this.#currentResultState = this.#currentQuery.state
632 this.#currentResultOptions = this.options
633
634 if (this.#currentResultState.data !== undefined) {
635 this.#lastQueryWithDefinedData = this.#currentQuery
636 }
637
638 // Only notify and update result if something has changed
639 if (shallowEqualObjects(nextResult, prevResult)) {
640 return
641 }
642
643 this.#currentResult = nextResult
644
645 const shouldNotifyListeners = (): boolean => {
646 if (!prevResult) {
647 return true
648 }
649
650 const { notifyOnChangeProps } = this.options
651 const notifyOnChangePropsValue =
652 typeof notifyOnChangeProps === 'function'
653 ? notifyOnChangeProps()
654 : notifyOnChangeProps
655
656 if (
657 notifyOnChangePropsValue === 'all' ||
658 (!notifyOnChangePropsValue && !this.#trackedProps.size)
659 ) {
660 return true
661 }
662
663 const includedProps = new Set(
664 notifyOnChangePropsValue ?? this.#trackedProps,
665 )
666
667 if (this.options.throwOnError) {
668 includedProps.add('error')
669 }
670
671 return Object.keys(this.#currentResult).some((key) => {
672 const typedKey = key as keyof QueryObserverResult
673 const changed = this.#currentResult[typedKey] !== prevResult[typedKey]
674
675 return changed && includedProps.has(typedKey)
676 })
677 }
678
679 this.#notify({ listeners: shouldNotifyListeners() })
680 }
681

Callers 13

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

Calls 3

createResultMethod · 0.95
#notifyMethod · 0.95
shallowEqualObjectsFunction · 0.90

Tested by

no test coverage detected