Skip to content

Commit 83cb10c

Browse files
committed
feat(devtools): forward tracked event payloads without breaking changs to updateState
1 parent 2df8375 commit 83cb10c

4 files changed

Lines changed: 7 additions & 34 deletions

File tree

docs/docs/with-devtools.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ The extensions don't activate during app initialization (as it is with `@ngrx/st
4141
import { updateState } from '@angular-architects/ngrx-toolkit';
4242
```
4343

44-
The Signal Store does not use the Redux pattern, so there are no action names involved by default. Instead, every action is referred to as a "Store Update". If you want to customize the action entry for better clarity, you can use the `updateState()` function instead of `patchState()`:
44+
The Signal Store does not use the Redux pattern, so there are no action names involved by default. Instead, every action is referred to as a "Store Update". If you want to customize the action name for better clarity, you can use the `updateState()` function instead of `patchState()`:
4545

4646
```typescript
4747
import { updateState } from '@angular-architects/ngrx-toolkit';
@@ -50,9 +50,6 @@ patchState(this.store, { loading: false });
5050

5151
// updateState is a wrapper around patchState and has an action name as second parameter
5252
updateState(this.store, 'update loading', { loading: false });
53-
54-
// updateState also accepts an action object with a mandatory type field
55-
updateState(this.store, { type: '[Book Store] bookSelected', payload: { bookId: '1' } }, { selectedBookId: '1' });
5653
```
5754

5855
## `renameDevtoolsName()`
@@ -175,7 +172,7 @@ const Store = signalStore(
175172
## Events tracking: `withTrackedReducer`
176173

177174
`withTrackedReducer` tracks state changes within the events
178-
plugin. This utility automatically derives the event entry, streamlining
175+
plugin. This utility automatically derives the event name, streamlining
179176
the tracking process.
180177

181178
To use it

libs/ngrx-toolkit/src/lib/devtools/tests/action-name.spec.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,4 @@ describe('updateState', () => {
4545
{ shop: { name: 'i4' } },
4646
);
4747
});
48-
49-
it('should set and send an action object', () => {
50-
const { sendSpy } = setupExtensions();
51-
52-
const Store = signalStore(
53-
{ providedIn: 'root' },
54-
withDevtools('shop'),
55-
withState({ name: 'Car' }),
56-
withMethods((store) => ({
57-
setName(name: string) {
58-
updateState(store, { type: 'Set Name', name }, { name });
59-
},
60-
})),
61-
);
62-
const store = TestBed.inject(Store);
63-
TestBed.flushEffects();
64-
65-
store.setName('i4');
66-
TestBed.flushEffects();
67-
68-
expect(sendSpy).toHaveBeenLastCalledWith(
69-
{ type: 'Set Name', name: 'i4' },
70-
{ shop: { name: 'i4' } },
71-
);
72-
});
7348
});

libs/ngrx-toolkit/src/lib/devtools/update-state.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
WritableStateSource,
55
} from '@ngrx/signals';
66
import { currentActionNames } from './internal/current-action-names';
7-
import { Action } from './internal/models';
87

98
type PatchFn = typeof originalPatchState extends (
109
arg1: infer First,
@@ -29,7 +28,7 @@ export const patchState: PatchFn = (state, action, ...rest) => {
2928
*/
3029
export function updateState<State extends object>(
3130
stateSource: WritableStateSource<State>,
32-
action: string | Action,
31+
action: string,
3332
...updaters: Array<
3433
Partial<NoInfer<State>> | PartialStateUpdater<NoInfer<State>>
3534
>

libs/ngrx-toolkit/src/lib/devtools/with-tracked-reducer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
EmptyFeatureResult,
44
getState,
55
PartialStateUpdater,
6+
patchState,
67
SignalStoreFeature,
78
signalStoreFeature,
89
type,
@@ -15,7 +16,7 @@ import {
1516
} from '@ngrx/signals/events';
1617
import { tap } from 'rxjs/operators';
1718
import { GLITCH_TRACKING_FEATURE } from './features/with-glitch-tracking';
18-
import { updateState } from './update-state';
19+
import { currentActionNames } from './internal/current-action-names';
1920
import { DEVTOOL_FEATURE_NAMES } from './with-devtools';
2021

2122
export function withTrackedReducer<State extends object>(
@@ -39,7 +40,8 @@ export function withTrackedReducer<State extends object>(
3940
const result = caseReducer.reducer(event, state);
4041
const updaters = Array.isArray(result) ? result : [result];
4142

42-
updateState(store, event, ...updaters);
43+
currentActionNames.add(event);
44+
patchState(store, ...updaters);
4345
}),
4446
),
4547
),

0 commit comments

Comments
 (0)