MCPcopy Create free account
hub / github.com/SvelteStack/svelte-query / setOptions

Method setOptions

src/queryCore/core/queryObserver.ts:139–207  ·  view source on GitHub ↗
(
    options?: QueryObserverOptions<
      TQueryFnData,
      TError,
      TData,
      TQueryData,
      TQueryKey
    >,
    notifyOptions?: NotifyOptions
  )

Source from the content-addressed store, hash-verified

137 }
138
139 setOptions(
140 options?: QueryObserverOptions<
141 TQueryFnData,
142 TError,
143 TData,
144 TQueryData,
145 TQueryKey
146 >,
147 notifyOptions?: NotifyOptions
148 ): void {
149 const prevOptions = this.options
150 const prevQuery = this.currentQuery
151
152 this.options = this.client.defaultQueryObserverOptions(options)
153
154 if (
155 typeof this.options.enabled !== 'undefined' &&
156 typeof this.options.enabled !== 'boolean'
157 ) {
158 throw new Error('Expected enabled to be a boolean')
159 }
160
161 // Keep previous query key if the user does not supply one
162 if (!this.options.queryKey) {
163 this.options.queryKey = prevOptions.queryKey
164 }
165
166 this.updateQuery()
167
168 const mounted = this.hasListeners()
169
170 // Fetch if there are subscribers
171 if (
172 mounted &&
173 shouldFetchOptionally(
174 this.currentQuery,
175 prevQuery,
176 this.options,
177 prevOptions
178 )
179 ) {
180 this.executeFetch()
181 }
182
183 // Update result
184 this.updateResult(notifyOptions)
185
186 // Update stale interval if needed
187 if (
188 mounted &&
189 (this.currentQuery !== prevQuery ||
190 this.options.enabled !== prevOptions.enabled ||
191 this.options.staleTime !== prevOptions.staleTime)
192 ) {
193 this.updateStaleTimeout()
194 }
195
196 const nextRefetchInterval = this.computeRefetchInterval()

Callers 2

constructorMethod · 0.95
updateOptionsMethod · 0.95

Calls 9

updateQueryMethod · 0.95
executeFetchMethod · 0.95
updateResultMethod · 0.95
updateStaleTimeoutMethod · 0.95
updateRefetchIntervalMethod · 0.95
shouldFetchOptionallyFunction · 0.85
hasListenersMethod · 0.80

Tested by

no test coverage detected