* 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
>,
)
| 94 | * ``` |
| 95 | */ |
| 96 | setOptions( |
| 97 | options: MutationObserverOptions< |
| 98 | TData, |
| 99 | TError, |
| 100 | TVariables, |
| 101 | TOnMutateResult |
| 102 | >, |
| 103 | ) { |
| 104 | const prevOptions = this.options as |
| 105 | | MutationObserverOptions<TData, TError, TVariables, TOnMutateResult> |
| 106 | | undefined |
| 107 | this.options = this.#client.defaultMutationOptions(options) |
| 108 | if (!shallowEqualObjects(this.options, prevOptions)) { |
| 109 | this.#client.getMutationCache().notify({ |
| 110 | type: 'observerOptionsUpdated', |
| 111 | mutation: this.#currentMutation, |
| 112 | observer: this, |
| 113 | }) |
| 114 | } |
| 115 | |
| 116 | if ( |
| 117 | prevOptions?.mutationKey && |
| 118 | this.options.mutationKey && |
| 119 | hashKey(prevOptions.mutationKey) !== hashKey(this.options.mutationKey) |
| 120 | ) { |
| 121 | this.reset() |
| 122 | } else if (this.#currentMutation?.state.status === 'pending') { |
| 123 | this.#currentMutation.setOptions(this.options) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | protected onSubscribe(): void { |
| 128 | if (this.listeners.size === 1 && this.#currentMutation) { |
no test coverage detected