MCPcopy Create free account
hub / github.com/TanStack/query / #notify

Method #notify

packages/query-core/src/mutationObserver.ts:169–234  ·  view source on GitHub ↗
(action?: Action<TData, TError, TVariables, TOnMutateResult>)

Source from the content-addressed store, hash-verified

167 }
168
169 #notify(action?: Action<TData, TError, TVariables, TOnMutateResult>): void {
170 notifyManager.batch(() => {
171 // First trigger the mutate callbacks
172 if (this.#mutateOptions && this.hasListeners()) {
173 const variables = this.#currentResult.variables!
174 const onMutateResult = this.#currentResult.context
175
176 const context = {
177 client: this.#client,
178 meta: this.options.meta,
179 mutationKey: this.options.mutationKey,
180 } satisfies MutationFunctionContext
181
182 if (action?.type === 'success') {
183 try {
184 this.#mutateOptions.onSuccess?.(
185 action.data,
186 variables,
187 onMutateResult,
188 context,
189 )
190 } catch (e) {
191 void Promise.reject(e)
192 }
193 try {
194 this.#mutateOptions.onSettled?.(
195 action.data,
196 null,
197 variables,
198 onMutateResult,
199 context,
200 )
201 } catch (e) {
202 void Promise.reject(e)
203 }
204 } else if (action?.type === 'error') {
205 try {
206 this.#mutateOptions.onError?.(
207 action.error,
208 variables,
209 onMutateResult,
210 context,
211 )
212 } catch (e) {
213 void Promise.reject(e)
214 }
215 try {
216 this.#mutateOptions.onSettled?.(
217 undefined,
218 action.error,
219 variables,
220 onMutateResult,
221 context,
222 )
223 } catch (e) {
224 void Promise.reject(e)
225 }
226 }

Callers 2

onMutationUpdateMethod · 0.95
resetMethod · 0.95

Calls 2

hasListenersMethod · 0.80
listenerFunction · 0.50

Tested by

no test coverage detected