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

Method #dispatch

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

Source from the content-addressed store, hash-verified

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

Callers 2

onContinueMethod · 0.95
executeMethod · 0.95

Calls 2

onMutationUpdateMethod · 0.80
notifyMethod · 0.45

Tested by

no test coverage detected