* Updates the observer's options. * * If the new `mutationKey` differs from the previous one (and both were * defined), the observer is reset, detaching it from the mutation it was * observing. Otherwise, if the currently observed mutation is still * `pending`, its options are updated
(
options: MutationObserverOptions<
TData,
TError,
TVariables,
TOnMutateResult
>,
)
| 98 | * ``` |
| 99 | */ |
| 100 | setOptions( |
| 101 | options: MutationObserverOptions< |
| 102 | TData, |
| 103 | TError, |
| 104 | TVariables, |
| 105 | TOnMutateResult |
| 106 | >, |
| 107 | ) { |
| 108 | const prevOptions = this.options as |
| 109 | | MutationObserverOptions<TData, TError, TVariables, TOnMutateResult> |
| 110 | | undefined |
| 111 | this.options = this.#client.defaultMutationOptions(options) |
| 112 | if (!shallowEqualObjects(this.options, prevOptions)) { |
| 113 | this.#client.getMutationCache().notify({ |
| 114 | type: 'observerOptionsUpdated', |
| 115 | mutation: this.#currentMutation, |
| 116 | observer: this, |
| 117 | }) |
| 118 | } |
| 119 | |
| 120 | if ( |
| 121 | prevOptions?.mutationKey && |
| 122 | this.options.mutationKey && |
| 123 | hashKey(prevOptions.mutationKey) !== hashKey(this.options.mutationKey) |
| 124 | ) { |
| 125 | this.reset() |
| 126 | } else if (this.#currentMutation?.state.status === 'pending') { |
| 127 | this.#currentMutation.setOptions(this.options) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | protected override onSubscribe(): void { |
| 132 | if (this.listeners.size === 1 && this.#currentMutation) { |
no test coverage detected