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

Method #dispatch

packages/query-core/src/mutation.ts:331–399  ·  view source on GitHub ↗
(action: Action<TData, TError, TVariables, TOnMutateResult>)

Source from the content-addressed store, hash-verified

329 }
330
331 #dispatch(action: Action<TData, TError, TVariables, TOnMutateResult>): void {
332 const reducer = (
333 state: MutationState<TData, TError, TVariables, TOnMutateResult>,
334 ): MutationState<TData, TError, TVariables, TOnMutateResult> => {
335 switch (action.type) {
336 case 'failed':
337 return {
338 ...state,
339 failureCount: action.failureCount,
340 failureReason: action.error,
341 }
342 case 'pause':
343 return {
344 ...state,
345 isPaused: true,
346 }
347 case 'continue':
348 return {
349 ...state,
350 isPaused: false,
351 }
352 case 'pending':
353 return {
354 ...state,
355 context: action.context,
356 data: undefined,
357 failureCount: 0,
358 failureReason: null,
359 error: null,
360 isPaused: action.isPaused,
361 status: 'pending',
362 variables: action.variables,
363 submittedAt: Date.now(),
364 }
365 case 'success':
366 return {
367 ...state,
368 data: action.data,
369 failureCount: 0,
370 failureReason: null,
371 error: null,
372 status: 'success',
373 isPaused: false,
374 }
375 case 'error':
376 return {
377 ...state,
378 data: undefined,
379 error: action.error,
380 failureCount: state.failureCount + 1,
381 failureReason: action.error,
382 isPaused: false,
383 status: 'error',
384 }
385 }
386 }
387 this.state = reducer(this.state)
388

Callers 2

onContinueMethod · 0.95
executeMethod · 0.95

Calls 2

onMutationUpdateMethod · 0.80
notifyMethod · 0.45

Tested by

no test coverage detected