Skip to content

Commit 9b2fc3a

Browse files
committed
feat: withDevTools disabled in prod docs
1 parent 27d146e commit 9b2fc3a

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
lines changed

README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ patchState(this.store, {loading: false});
7676
updateState(this.store 'update loading', {loading: false});
7777
```
7878

79-
`withDevtools()` is by default disabled in production mode, however if you want to tree-shake it from the application bundle you need to abstract it in your environment file.
79+
`withDevtools()` is by default enabled in production mode, if you want to tree-shake it from the application bundle you need to abstract it in your environment file.
8080

8181
<details>
8282

@@ -87,23 +87,25 @@ updateState(this.store 'update loading', {loading: false});
8787
import { withDevtools } from '@angular-architects/ngrx-toolkit';
8888

8989
export const environment = {
90-
storeDevToolsFeature: withDevtools
90+
storeWithDevTools: withDevtools
9191
}
9292
```
9393

9494
environment.prod.ts
9595
```typescript
96+
import { withDevtoolsStub } from '@angular-architects/ngrx-toolkit';
97+
9698
export const environment = {
97-
storeDevToolsFeature: (_: string): SignalStoreFeature => store => store
99+
storeWithDevTools: withDevToolsStub
98100
}
99101
```
100102

101-
Then all you need to do is replace `withDevTools` everywhere in your app with `environment.storeDevToolsFeature`
103+
Then all you need to do is replace `withDevTools` everywhere in your app with `environment.storeWithDevTools`
102104
e.g.:
103105
```typescript
104106
export const SomeStore = signalStore(
105107
withState({strings: [] as string[] }),
106-
environment.storeDevToolsFeature('some')
108+
environment.storeWithDevTools('featureName')
107109
);
108110
```
109111

libs/ngrx-toolkit/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export {
2+
withDevToolsStub,
23
withDevtools,
34
patchState,
45
updateState,

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

-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
let isDevMode = true;
2-
jest.mock('@angular/core', () => ({ ...jest.requireActual('@angular/core'), isDevMode: () => isDevMode }))
3-
41
import { signalStore } from '@ngrx/signals';
52
import { withEntities } from '@ngrx/signals/entities';
63
import { Action, withDevtools } from './with-devtools';
@@ -34,7 +31,6 @@ const createFlight = (flight: Partial<Flight> = {}) => ({
3431
interface SetupOptions {
3532
extensionsAvailable: boolean;
3633
inSsr: boolean;
37-
isDevMode: boolean
3834
}
3935

4036
interface TestData {
@@ -52,12 +48,9 @@ function run(
5248
const defaultOptions: SetupOptions = {
5349
inSsr: false,
5450
extensionsAvailable: true,
55-
isDevMode: true,
5651
};
5752
const realOptions = { ...defaultOptions, ...options };
5853

59-
isDevMode = realOptions.isDevMode;
60-
6154
const sendSpy = jest.fn<void, [Action, Record<string, unknown>]>();
6255
const connection = {
6356
send: sendSpy,
@@ -123,16 +116,6 @@ describe('Devtools', () => {
123116
)
124117
);
125118

126-
it(
127-
'should not connect if it runs in production',
128-
run(
129-
({ connectSpy }) => {
130-
expect(connectSpy).toHaveBeenCalledTimes(0);
131-
},
132-
{ isDevMode: false }
133-
)
134-
);
135-
136119
it(
137120
'should dispatch todo state',
138121
run(({ sendSpy, runEffects }) => {

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
SignalStoreFeature,
66
WritableStateSource,
77
} from '@ngrx/signals';
8-
import { effect, inject, isDevMode, PLATFORM_ID, signal, Signal } from '@angular/core';
8+
import { effect, inject, PLATFORM_ID, signal, Signal } from '@angular/core';
99
import { isPlatformServer } from '@angular/common';
1010
import { Prettify } from './shared/prettify';
1111

@@ -79,6 +79,11 @@ export function reset() {
7979
storeRegistry.set({});
8080
}
8181

82+
/**
83+
* Stub for DevTools integration. Can be used to disable DevTools in production.
84+
*/
85+
export const withDevToolsStub: typeof withDevtools = () => store => store;
86+
8287
/**
8388
* @param name store's name as it should appear in the DevTools
8489
*/
@@ -87,7 +92,7 @@ export function withDevtools<Input extends EmptyFeatureResult>(
8792
): SignalStoreFeature<Input, EmptyFeatureResult> {
8893
return (store) => {
8994
const isServer = isPlatformServer(inject(PLATFORM_ID));
90-
if (isServer || !isDevMode()) {
95+
if (isServer) {
9196
return store;
9297
}
9398

0 commit comments

Comments
 (0)