MCPcopy
hub / github.com/TanStack/query / #dispatch

Method #dispatch

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

Source from the content-addressed store, hash-verified

313 }
314
315 #dispatch(action: Action<TData, TError, TVariables, TOnMutateResult>): void {
316 const reducer = (
317 state: MutationState<TData, TError, TVariables, TOnMutateResult>,
318 ): MutationState<TData, TError, TVariables, TOnMutateResult> => {
319 switch (action.type) {
320 case 'failed':
321 return {
322 ...state,
323 failureCount: action.failureCount,
324 failureReason: action.error,
325 }
326 case 'pause':
327 return {
328 ...state,
329 isPaused: true,
330 }
331 case 'continue':
332 return {
333 ...state,
334 isPaused: false,
335 }
336 case 'pending':
337 return {
338 ...state,
339 context: action.context,
340 data: undefined,
341 failureCount: 0,
342 failureReason: null,
343 error: null,
344 isPaused: action.isPaused,
345 status: 'pending',
346 variables: action.variables,
347 submittedAt: Date.now(),
348 }
349 case 'success':
350 return {
351 ...state,
352 data: action.data,
353 failureCount: 0,
354 failureReason: null,
355 error: null,
356 status: 'success',
357 isPaused: false,
358 }
359 case 'error':
360 return {
361 ...state,
362 data: undefined,
363 error: action.error,
364 failureCount: state.failureCount + 1,
365 failureReason: action.error,
366 isPaused: false,
367 status: 'error',
368 }
369 }
370 }
371 this.state = reducer(this.state)
372

Callers 2

onContinueMethod · 0.95
executeMethod · 0.95

Calls 2

onMutationUpdateMethod · 0.80
notifyMethod · 0.45

Tested by

no test coverage detected