* 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.
()
| 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() |
no test coverage detected