Skip to content

Commit ead5fa0

Browse files
fix(redux): don't override methods of innerStore (#132)
As discussed in #128
1 parent 2495379 commit ead5fa0

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

libs/ngrx-toolkit/src/lib/with-redux.spec.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { patchState, signalStore, withState } from '@ngrx/signals';
1+
import { patchState, signalStore, withMethods, withState } from '@ngrx/signals';
22
import { inject } from '@angular/core';
33
import {
44
HttpClient,
@@ -228,4 +228,31 @@ describe('with redux', () => {
228228
expect(flightStore.effect1()).toBe(true);
229229
expect(flightStore.effect2()).toBe(true);
230230
});
231+
232+
it('should not override methods defined before', () => {
233+
const FlightsStore = signalStore(
234+
withMethods(() => ({
235+
sayHi() {
236+
return 'hi';
237+
},
238+
})),
239+
withRedux({
240+
actions: {
241+
init: noPayload,
242+
},
243+
reducer() {
244+
return {};
245+
},
246+
effects() {
247+
return {};
248+
},
249+
})
250+
);
251+
252+
const flightStore = TestBed.configureTestingModule({
253+
providers: [FlightsStore],
254+
}).inject(FlightsStore);
255+
256+
expect(flightStore.sayHi()).toBe('hi');
257+
});
231258
});

libs/ngrx-toolkit/src/lib/with-redux.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ export function withRedux<
379379
);
380380
return {
381381
...store,
382-
methods,
382+
methods: { ...store.methods, ...methods },
383383
};
384384
};
385385
}

0 commit comments

Comments
 (0)