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

Method #notify

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

Source from the content-addressed store, hash-verified

238 }
239
240 #notify(action?: Action<TData, TError, TVariables, TOnMutateResult>): void {
241 notifyManager.batch(() => {
242 // First trigger the mutate callbacks
243 if (this.#mutateOptions && this.hasListeners()) {
244 const variables = this.#currentResult.variables!
245 const onMutateResult = this.#currentResult.context
246
247 const context = {
248 client: this.#client,
249 meta: this.options.meta,
250 mutationKey: this.options.mutationKey,
251 } satisfies MutationFunctionContext
252
253 if (action?.type === 'success') {
254 try {
255 this.#mutateOptions.onSuccess?.(
256 action.data,
257 variables,
258 onMutateResult,
259 context,
260 )
261 } catch (e) {
262 void Promise.reject(e)
263 }
264 try {
265 this.#mutateOptions.onSettled?.(
266 action.data,
267 null,
268 variables,
269 onMutateResult,
270 context,
271 )
272 } catch (e) {
273 void Promise.reject(e)
274 }
275 } else if (action?.type === 'error') {
276 try {
277 this.#mutateOptions.onError?.(
278 action.error,
279 variables,
280 onMutateResult,
281 context,
282 )
283 } catch (e) {
284 void Promise.reject(e)
285 }
286 try {
287 this.#mutateOptions.onSettled?.(
288 undefined,
289 action.error,
290 variables,
291 onMutateResult,
292 context,
293 )
294 } catch (e) {
295 void Promise.reject(e)
296 }
297 }

Callers 2

onMutationUpdateMethod · 0.95
resetMethod · 0.95

Calls 2

hasListenersMethod · 0.80
listenerFunction · 0.50

Tested by

no test coverage detected