* 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.
()
| 733 | * update was missed in the gap between creating the observer and subscribing to it. |
| 734 | */ |
| 735 | updateResult(): void { |
| 736 | const prevResult = this.#currentResult as |
| 737 | | QueryObserverResult<TData, TError> |
| 738 | | undefined |
| 739 | |
| 740 | const nextResult = this.createResult(this.#currentQuery, this.options) |
| 741 | |
| 742 | this.#currentResultState = this.#currentQuery.state |
| 743 | this.#currentResultOptions = this.options |
| 744 | |
| 745 | if (this.#currentResultState.data !== undefined) { |
| 746 | this.#lastQueryWithDefinedData = this.#currentQuery |
| 747 | } |
| 748 | |
| 749 | // Only notify and update result if something has changed |
| 750 | if (shallowEqualObjects(nextResult, prevResult)) { |
| 751 | return |
| 752 | } |
| 753 | |
| 754 | this.#currentResult = nextResult |
| 755 | |
| 756 | const shouldNotifyListeners = (): boolean => { |
| 757 | if (!prevResult) { |
| 758 | return true |
| 759 | } |
| 760 | |
| 761 | const { notifyOnChangeProps } = this.options |
| 762 | const notifyOnChangePropsValue = |
| 763 | typeof notifyOnChangeProps === 'function' |
| 764 | ? notifyOnChangeProps() |
| 765 | : notifyOnChangeProps |
| 766 | |
| 767 | if ( |
| 768 | notifyOnChangePropsValue === 'all' || |
| 769 | (!notifyOnChangePropsValue && !this.#trackedProps.size) |
| 770 | ) { |
| 771 | return true |
| 772 | } |
| 773 | |
| 774 | const includedProps = new Set( |
| 775 | notifyOnChangePropsValue ?? this.#trackedProps, |
| 776 | ) |
| 777 | |
| 778 | if (this.options.throwOnError) { |
| 779 | includedProps.add('error') |
| 780 | } |
| 781 | |
| 782 | return Object.keys(this.#currentResult).some((key) => { |
| 783 | const typedKey = key as keyof QueryObserverResult |
| 784 | const changed = this.#currentResult[typedKey] !== prevResult[typedKey] |
| 785 | |
| 786 | return changed && includedProps.has(typedKey) |
| 787 | }) |
| 788 | } |
| 789 | |
| 790 | const notifyListeners = shouldNotifyListeners() |
| 791 | |
| 792 | notifyManager.batch(() => { |
no test coverage detected