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

Method updateResult

packages/query-core/src/queryObserver.ts:766–839  ·  view source on GitHub ↗

* Recomputes and stores the current result from the current query/options, notifying listeners * if it changed. Framework adapters call this right after subscribing to make sure no query * update was missed in the gap between creating the observer and subscribing to it.

()

Source from the content-addressed store, hash-verified

764 * update was missed in the gap between creating the observer and subscribing to it.
765 */
766 updateResult(): void {
767 const prevResult = this.#currentResult as
768 | QueryObserverResult<TData, TError>
769 | undefined
770
771 const nextResult = this.createResult(this.#currentQuery, this.options)
772
773 this.#currentResultState = this.#currentQuery.state
774 this.#currentResultOptions = this.options
775
776 if (this.#currentResultState.data !== undefined) {
777 this.#lastQueryWithDefinedData = this.#currentQuery
778 }
779
780 // Only notify and update result if something has changed
781 if (shallowEqualObjects(nextResult, prevResult)) {
782 return
783 }
784
785 this.#currentResult = nextResult
786
787 const shouldNotifyListeners = (): boolean => {
788 if (!prevResult) {
789 return true
790 }
791
792 const { notifyOnChangeProps } = this.options
793 const notifyOnChangePropsValue =
794 typeof notifyOnChangeProps === 'function'
795 ? notifyOnChangeProps()
796 : notifyOnChangeProps
797
798 if (
799 notifyOnChangePropsValue === 'all' ||
800 (!notifyOnChangePropsValue && !this.#trackedProps.size)
801 ) {
802 return true
803 }
804
805 if (
806 this.options.throwOnError &&
807 this.#currentResult.error !== prevResult.error
808 ) {
809 return true
810 }
811
812 for (const key of notifyOnChangePropsValue ?? this.#trackedProps) {
813 if (
814 this.#currentResult[key as keyof QueryObserverResult] !==
815 prevResult[key as keyof QueryObserverResult]
816 ) {
817 return true
818 }
819 }
820 return false
821 }
822
823 const notifyListeners = shouldNotifyListeners()

Callers 14

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 5

createResultMethod · 0.95
shallowEqualObjectsFunction · 0.90
getQueryCacheMethod · 0.80
listenerFunction · 0.50
notifyMethod · 0.45

Tested by

no test coverage detected