* docs(*): add parameter and result property tables to reference function pages and an overview to overloaded ones * docs(*): link to the base type's properties when a parameter or result type has no property table * docs(framework/*/reference): regenerate reference docs * docs(framework/*/reference): regenerate reference docs * chore(scripts/generate-docs): restore the 'dirname' import that the merge dropped * docs(framework/*/reference): regenerate reference docs * docs(scripts/generate-docs): label overloads in the overview with their declared parameter and return types * docs(framework/*/reference): regenerate reference docs * docs(scripts/generate-docs): convert declared intersection types from the source so signatures keep their alias names * docs(framework/*/reference): regenerate reference docs * docs(scripts/generate-docs): reword a comment to avoid the unknown word 'inlines' * docs(scripts/generate-docs): skip a parameter table on overloaded pages when its heading is missing
2.8 KiB
| id | title |
|---|---|
| injectMutationState | injectMutationState |
function injectMutationState<TResult>(injectMutationStateFn?: () => MutationStateOptions<TResult>, options?: InjectMutationStateOptions): Signal<TResult[]>;
Defined in: packages/angular-query-experimental/src/inject-mutation-state.ts:114
Injects a signal that gives you access to all mutations in the MutationCache. You can pass filters
(MutationFilters) to narrow down your mutations, and select to transform the mutation state.
Type Parameters
TResult
TResult = MutationState<unknown, Error, unknown, unknown>
Parameters
injectMutationStateFn?
() => MutationStateOptions<TResult>
A function returning the filters to narrow down matched mutations, and an
optional select to transform the mutation state. Similar to computed from Angular, this function runs
in the reactive context, so signals read inside it re-narrow the matched mutations.
options?
Additional configuration
options properties
| Property | Type | Description |
|---|---|---|
injector? |
Injector |
The Injector in which to create the mutation state signal. If this is not provided, the current injection context will be used instead (via inject). |
Returns
Signal<TResult[]>
A Signal with an Array of whatever select returns for each matching mutation.
Examples
Get all variables of all running mutations:
@Component({
selector: 'pending-posts',
template: `{{ pendingVariables().length }} posts saving...`,
})
export class PendingPosts {
readonly pendingVariables = injectMutationState(() => ({
filters: { status: 'pending' },
select: (mutation) => mutation.state.variables,
}))
}
Get all data for specific mutations via the mutationKey:
const mutationKey = ['posts']
@Component({
selector: 'posts',
template: `
<button (click)="createPost()">
Create post ({{ savedPosts().length }} saved so far)
</button>
`,
})
export class Posts {
// Some mutation that we want to get the state for
readonly createPostMutation = injectMutation(() => ({
mutationKey,
mutationFn: createPosts,
}))
readonly savedPosts = injectMutationState(() => ({
// this mutation key needs to match the mutation key of the given mutation (see above)
filters: { mutationKey, status: 'success' },
select: (mutation) => mutation.state.data,
}))
createPost() {
this.createPostMutation.mutate(['New Post'])
}
}