MCPcopy Create free account
hub / github.com/TanStack/query / injectMutationState

Function injectMutationState

packages/angular-query/src/inject-mutation-state.ts:118–142  ·  view source on GitHub ↗
(
  options: () => MutationStateOptions<TResult, TMutation> = () => ({}),
)

Source from the content-addressed store, hash-verified

116 * ```
117 */
118export function injectMutationState<
119 TResult = MutationState,
120 TMutation extends Mutation<any, any, any, any> =
121 MutationTypeFromResult<TResult>,
122>(
123 options: () => MutationStateOptions<TResult, TMutation> = () => ({}),
124): Signal<Array<TResult>> {
125 if (typeof ngDevMode === 'undefined' || ngDevMode) {
126 assertInInjectionContext(injectMutationState)
127 }
128 const queryClient = inject(QueryClient)
129 const mutationCache = queryClient.getMutationCache()
130
131 return injectExternalStore(
132 () => ({
133 getSnapshot: () => getResult(mutationCache, options()),
134 subscribe: (onStoreChange) => mutationCache.subscribe(onStoreChange),
135 }),
136 {
137 equal: (previous, next) =>
138 previous.length === next.length &&
139 previous.every((value, index) => Object.is(value, next[index])),
140 },
141 )
142}

Calls 5

injectExternalStoreFunction · 0.90
getMutationCacheMethod · 0.80
getResultFunction · 0.70
optionsFunction · 0.50
subscribeMethod · 0.45

Tested by

no test coverage detected