Skip to main content

Function: withMutations()

withMutations<Input, Result>(mutationsFactory): SignalStoreFeature<Input, NamedMutationResult<Result>>

Defined in: libs/ngrx-toolkit/src/lib/with-mutations.ts:76

Adds mutation methods to the store. Also, for each mutation method, several Signals are added informing about the mutation's status and errors.

export type Params = {
value: number;
};

export const CounterStore = signalStore(
{ providedIn: 'root' },
withState({ counter: 0 }),
withMutations((store) => ({
increment: rxMutation({ ... }),
})),
);

There are several types of mutations. In the example shown, an module:rx-mutation.rxMutation | rxMutation leveraging RxJS is used

For the defined increment mutation, several the following properties and methods are added to the store:

  • increment(params: Params): Promise<MutationResult<number>>: The mutation method.
  • incrementIsPending: A signal indicating if the mutation is in progress.
  • incrementStatus: A signal representing the current status of the mutation.
  • incrementError: A signal containing any error that occurred during the mutation.

Type Parameters

Input extends SignalStoreFeatureResult

Result extends MutationsDictionary

Parameters

mutationsFactory

(store) => Result

Returns

SignalStoreFeature<Input, NamedMutationResult<Result>>