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