(
options: QueryObserverOptions<
TQueryFnData,
TError,
TData,
TQueryData,
TQueryKey
>,
)
| 132 | } |
| 133 | |
| 134 | setOptions( |
| 135 | options: QueryObserverOptions< |
| 136 | TQueryFnData, |
| 137 | TError, |
| 138 | TData, |
| 139 | TQueryData, |
| 140 | TQueryKey |
| 141 | >, |
| 142 | ): void { |
| 143 | const prevOptions = this.options |
| 144 | const prevQuery = this.#currentQuery |
| 145 | |
| 146 | this.options = this.#client.defaultQueryOptions(options) |
| 147 | |
| 148 | if ( |
| 149 | this.options.enabled !== undefined && |
| 150 | typeof this.options.enabled !== 'boolean' && |
| 151 | typeof this.options.enabled !== 'function' && |
| 152 | typeof resolveQueryBoolean(this.options.enabled, this.#currentQuery) !== |
| 153 | 'boolean' |
| 154 | ) { |
| 155 | throw new Error( |
| 156 | 'Expected enabled to be a boolean or a callback that returns a boolean', |
| 157 | ) |
| 158 | } |
| 159 | |
| 160 | this.#updateQuery() |
| 161 | this.#currentQuery.setOptions(this.options) |
| 162 | |
| 163 | if ( |
| 164 | prevOptions._defaulted && |
| 165 | !shallowEqualObjects(this.options, prevOptions) |
| 166 | ) { |
| 167 | this.#client.getQueryCache().notify({ |
| 168 | type: 'observerOptionsUpdated', |
| 169 | query: this.#currentQuery, |
| 170 | observer: this, |
| 171 | }) |
| 172 | } |
| 173 | |
| 174 | const mounted = this.hasListeners() |
| 175 | |
| 176 | // Fetch if there are subscribers |
| 177 | if ( |
| 178 | mounted && |
| 179 | shouldFetchOptionally( |
| 180 | this.#currentQuery, |
| 181 | prevQuery, |
| 182 | this.options, |
| 183 | prevOptions, |
| 184 | ) |
| 185 | ) { |
| 186 | this.#executeFetch() |
| 187 | } |
| 188 | |
| 189 | // Update result |
| 190 | this.updateResult() |
| 191 |
no test coverage detected