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

Method #dispatch

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

Source from the content-addressed store, hash-verified

445 }
446
447 #dispatch(action: Action<TData, TError, TVariables, TOnMutateResult>): void {
448 const reducer = (
449 state: MutationState<TData, TError, TVariables, TOnMutateResult>,
450 ): MutationState<TData, TError, TVariables, TOnMutateResult> => {
451 switch (action.type) {
452 case 'failed':
453 return {
454 ...state,
455 failureCount: action.failureCount,
456 failureReason: action.error,
457 }
458 case 'pause':
459 return {
460 ...state,
461 isPaused: true,
462 }
463 case 'continue':
464 return {
465 ...state,
466 isPaused: false,
467 }
468 case 'pending':
469 return {
470 ...state,
471 context: action.context,
472 data: undefined,
473 failureCount: 0,
474 failureReason: null,
475 error: null,
476 isPaused: action.isPaused,
477 status: 'pending',
478 variables: action.variables,
479 submittedAt: Date.now(),
480 }
481 case 'success':
482 return {
483 ...state,
484 data: action.data,
485 failureCount: 0,
486 failureReason: null,
487 error: null,
488 status: 'success',
489 isPaused: false,
490 }
491 case 'error':
492 return {
493 ...state,
494 data: undefined,
495 error: action.error,
496 failureCount: state.failureCount + 1,
497 failureReason: action.error,
498 isPaused: false,
499 status: 'error',
500 }
501 }
502 }
503 this.state = reducer(this.state)
504

Callers 2

onContinueMethod · 0.95
executeMethod · 0.95

Calls 2

onMutationUpdateMethod · 0.80
notifyMethod · 0.45

Tested by

no test coverage detected