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