From dba4769fd7f2709ef1413dadfeab42ba1644b838 Mon Sep 17 00:00:00 2001 From: Michael Small Date: Tue, 24 Feb 2026 21:31:49 -0600 Subject: [PATCH 1/3] fix: assign properties of mutations in withMutation --- libs/ngrx-toolkit/src/lib/with-mutations.ts | 27 +++++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/libs/ngrx-toolkit/src/lib/with-mutations.ts b/libs/ngrx-toolkit/src/lib/with-mutations.ts index 5922307a..8586c1c5 100644 --- a/libs/ngrx-toolkit/src/lib/with-mutations.ts +++ b/libs/ngrx-toolkit/src/lib/with-mutations.ts @@ -118,14 +118,25 @@ function createMutationsFeature( keys.reduce( (acc, key) => ({ ...acc, - [key]: async (params: never) => { - const mutation = mutations[key]; - if (!mutation) { - throw new Error(`Mutation ${key} not found`); - } - const result = await mutation(params); - return result; - }, + [key]: Object.assign( + async (params: never) => { + const mutation = mutations[key]; + if (!mutation) { + throw new Error(`Mutation ${key} not found`); + } + const result = await mutation(params); + + return result; + }, + { + status: mutations[key].status, + value: mutations[key].value, + isPending: mutations[key].isPending, + isSuccess: mutations[key].isSuccess, + error: mutations[key].error, + hasValue: mutations[key].hasValue, + }, + ), }), {} as MethodsDictionary, ), From 7546899881fc3b47847492bdcfc3f77f8faefd01 Mon Sep 17 00:00:00 2001 From: Michael Small Date: Sun, 10 May 2026 11:04:42 -0500 Subject: [PATCH 2/3] fix: reassign mutation whole, rather than subset of props --- libs/ngrx-toolkit/src/lib/with-mutations.ts | 25 ++++++++------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/libs/ngrx-toolkit/src/lib/with-mutations.ts b/libs/ngrx-toolkit/src/lib/with-mutations.ts index 8586c1c5..7cb142b0 100644 --- a/libs/ngrx-toolkit/src/lib/with-mutations.ts +++ b/libs/ngrx-toolkit/src/lib/with-mutations.ts @@ -118,25 +118,18 @@ function createMutationsFeature( keys.reduce( (acc, key) => ({ ...acc, - [key]: Object.assign( - async (params: never) => { - const mutation = mutations[key]; - if (!mutation) { - throw new Error(`Mutation ${key} not found`); - } + [key]: (() => { + const mutation = mutations[key]; + if (!mutation) { + throw new Error(`Mutation ${key} not found`); + } + + return Object.assign(async (params: never) => { const result = await mutation(params); return result; - }, - { - status: mutations[key].status, - value: mutations[key].value, - isPending: mutations[key].isPending, - isSuccess: mutations[key].isSuccess, - error: mutations[key].error, - hasValue: mutations[key].hasValue, - }, - ), + }, mutation); + })(), }), {} as MethodsDictionary, ), From 1056989c0fc053d44291317e2bf40ca236f62caa Mon Sep 17 00:00:00 2001 From: Michael Small Date: Tue, 12 May 2026 21:43:50 -0500 Subject: [PATCH 3/3] chore: add test for mutations property assignment --- .../src/lib/with-mutations.spec.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libs/ngrx-toolkit/src/lib/with-mutations.spec.ts b/libs/ngrx-toolkit/src/lib/with-mutations.spec.ts index 5bb3a80d..7faff07f 100644 --- a/libs/ngrx-toolkit/src/lib/with-mutations.spec.ts +++ b/libs/ngrx-toolkit/src/lib/with-mutations.spec.ts @@ -116,6 +116,31 @@ function createTestSetup(flatteningOperator = concatOp) { } describe('withMutations with rxMutation', () => { + // fix: assign properties of mutations in withMutation https://github.com/angular-architects/ngrx-toolkit/pull/288 + it("does not lose the runtime properties of a mutation's direct reference when assigning it to a component field", fakeAsync(() => { + const testSetup = createTestSetup(); + const store = testSetup.store; + + // Simulates `readonly myMutation = this.store.increment` in a component. + const myMutation = store.increment; + + expect(myMutation.status()).toEqual('idle'); + expect(typeof myMutation.isPending).toEqual('function'); + expect(myMutation.isPending()).toEqual(false); + + myMutation(2); + expect(myMutation.status()).toEqual('pending'); + expect(myMutation.isPending()).toEqual(true); + + tick(2000); + + expect(myMutation.status()).toEqual('success'); + expect(myMutation.isPending()).toEqual(false); + expect(myMutation.error()).toEqual(undefined); + + expect(store.counter()).toEqual(7); + })); + it('should update the state', fakeAsync(() => { const testSetup = createTestSetup(); const store = testSetup.store;