import { Injector, Signal } from '@angular/core'; import { Mutation, MutationFilters, MutationState } from '@tanstack/query-core'; type MutationStateOptions = { filters?: MutationFilters; select?: (mutation: Mutation) => TResult; }; export interface InjectMutationStateOptions { /** * 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`). */ injector?: Injector; } /** * Injects a signal that gives you access to all mutations in the `MutationCache`. You can pass `filters` * ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the mutation state. * * @param injectMutationStateFn - 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. * @param options - Additional configuration * @returns A `Signal` with an Array of whatever `select` returns for each matching mutation. * * @example * Get all variables of all running mutations: * ```angular-ts * @Component({ * selector: 'pending-posts', * template: `{{ pendingVariables().length }} posts saving...`, * }) * export class PendingPosts { * readonly pendingVariables = injectMutationState(() => ({ * filters: { status: 'pending' }, * select: (mutation) => mutation.state.variables, * })) * } * ``` * * @example * Get all data for specific mutations via the `mutationKey`: * ```angular-ts * const mutationKey = ['posts'] * * @Component({ * selector: 'posts', * template: ` * * `, * }) * 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']) * } * } * ``` */ export declare function injectMutationState(injectMutationStateFn?: () => MutationStateOptions, options?: InjectMutationStateOptions): Signal>; export {};