Skip to content

Commit 4e8b74c

Browse files
refactor(devtools): use getState instead of direct signal access
1 parent 169a3ce commit 4e8b74c

File tree

4 files changed

+18
-41
lines changed

4 files changed

+18
-41
lines changed

libs/ngrx-toolkit/src/lib/devtools/internal/devtools-syncer.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import {
44
Injectable,
55
OnDestroy,
66
PLATFORM_ID,
7-
Signal,
87
signal,
98
} from '@angular/core';
109
import { currentActionNames } from './currrent-action-names';
11-
import { isPlatformBrowser, isPlatformServer } from '@angular/common';
10+
import { isPlatformBrowser } from '@angular/common';
1211
import { Connection, DevtoolsOptions } from '../with-devtools';
12+
import { getState, StateSource } from '@ngrx/signals';
1313

1414
const dummyConnection: Connection = {
1515
send: () => void true,
@@ -64,7 +64,7 @@ export class DevtoolsSyncer implements OnDestroy {
6464
for (const name in stores) {
6565
this.#syncedStoreNames.add(name);
6666
const { store } = stores[name];
67-
rootState[name] = store();
67+
rootState[name] = getState(store);
6868
}
6969

7070
const names = Array.from(currentActionNames);
@@ -79,7 +79,7 @@ export class DevtoolsSyncer implements OnDestroy {
7979
currentActionNames.clear();
8080
}
8181

82-
addStore(name: string, store: Signal<unknown>, options: DevtoolsOptions) {
82+
addStore(name: string, store: StateSource<object>, options: DevtoolsOptions) {
8383
let storeName = name;
8484
const names = Object.keys(this.#stores());
8585

@@ -143,5 +143,5 @@ Enable automatic indexing via withDevTools('${storeName}', { indexNames: true })
143143

144144
type StoreRegistry = Record<
145145
string,
146-
{ store: Signal<unknown>; options: DevtoolsOptions }
146+
{ store: StateSource<object>; options: DevtoolsOptions }
147147
>;

libs/ngrx-toolkit/src/lib/devtools/internal/get-store-signal.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { renameDevtoolsName } from '../rename-devtools-name';
1212

1313
describe('withDevtools / renaming', () => {
14-
it('should automatically index multiple instances', waitForAsync(() => {
14+
it('should automatically index multiple instances', () => {
1515
const { sendSpy } = setupExtensions();
1616
const Store = signalStore(
1717
{ providedIn: 'root' },
@@ -36,9 +36,9 @@ describe('withDevtools / renaming', () => {
3636
'flights-1': { airline: 'Lufthansa' },
3737
}
3838
);
39-
}));
39+
});
4040

41-
it('not index, if multiple instances do not exist simultaneously', waitForAsync(async () => {
41+
it('not index, if multiple instances do not exist simultaneously', () => {
4242
const { sendSpy } = setupExtensions();
4343
const Store = signalStore(
4444
withDevtools('flights'),
@@ -78,9 +78,9 @@ describe('withDevtools / renaming', () => {
7878
},
7979
],
8080
]);
81-
}));
81+
});
8282

83-
it('should throw if automatic indexing is disabled', waitForAsync(() => {
83+
it('should throw if automatic indexing is disabled', () => {
8484
setupExtensions();
8585
const Store = signalStore(
8686
{ providedIn: 'root' },
@@ -100,7 +100,7 @@ describe('withDevtools / renaming', () => {
100100
`An instance of the store flights already exists. \
101101
Enable automatic indexing via withDevTools('flights', { indexNames: true }), or rename it upon instantiation.`
102102
);
103-
}));
103+
});
104104

105105
it('should throw if name already exists', () => {
106106
const { sendSpy } = setupExtensions();
@@ -111,7 +111,7 @@ Enable automatic indexing via withDevTools('flights', { indexNames: true }), or
111111
});
112112

113113
describe('renaming', () => {
114-
it('should allow to rename the store before first sync', waitForAsync(async () => {
114+
it('should allow to rename the store before first sync', () => {
115115
const { sendSpy } = setupExtensions();
116116

117117
const Store = signalStore(
@@ -128,9 +128,9 @@ Enable automatic indexing via withDevTools('flights', { indexNames: true }), or
128128
{ type: 'Store Update' },
129129
{ flights: { name: 'Product', price: 10.5 } }
130130
);
131-
}));
131+
});
132132

133-
it('should throw on rename after sync', waitForAsync(async () => {
133+
it('should throw on rename after sync', () => {
134134
setupExtensions();
135135
const Store = signalStore(
136136
{ providedIn: 'root' },
@@ -144,9 +144,9 @@ Enable automatic indexing via withDevTools('flights', { indexNames: true }), or
144144
expect(() => renameDevtoolsName(store, 'flights')).toThrow(
145145
'NgRx Toolkit/DevTools: cannot rename from flight to flights. flight has already been send to DevTools.'
146146
);
147-
}));
147+
});
148148

149-
it('should throw on rename if name already exists', waitForAsync(async () => {
149+
it('should throw on rename if name already exists', () => {
150150
setupExtensions();
151151
signalStore(
152152
{ providedIn: 'root' },
@@ -165,7 +165,7 @@ Enable automatic indexing via withDevTools('flights', { indexNames: true }), or
165165
expect(() => renameDevtoolsName(store, 'shop')).toThrow(
166166
'NgRx Toolkit/DevTools: cannot rename from mall to shop. mall has already been send to DevTools.'
167167
);
168-
}));
168+
});
169169

170170
it('should throw if applied to a SignalStore without DevTools', () => {
171171
setupExtensions();

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { signalStoreFeature, withHooks, withMethods } from '@ngrx/signals';
22
import { inject } from '@angular/core';
33
import { DevtoolsSyncer } from './internal/devtools-syncer.service';
4-
import { getStoreSignal } from './internal/get-store-signal';
54

65
export type Action = { type: string };
76
export type Connection = {
@@ -82,7 +81,7 @@ export function withDevtools(
8281
return signalStoreFeature(
8382
withMethods((store) => {
8483
const syncer = inject(DevtoolsSyncer);
85-
syncer.addStore(name, getStoreSignal(store), finalOptions);
84+
syncer.addStore(name, store, finalOptions);
8685

8786
return {
8887
[renameDevtoolsMethodName]: (newName: string) => {

0 commit comments

Comments
 (0)