Skip to content

Commit

Permalink
feat: withDevTools disabled in prod, and tree-shaking docs
Browse files Browse the repository at this point in the history
  • Loading branch information
marcindz88 authored and rainerhahnekamp committed Oct 18, 2024
1 parent 4c38b99 commit 4c2baa9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,52 @@ patchState(this.store, { loading: false });
updateState(this.store, 'update loading', { loading: false });
```

`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.

<details>

<summary>Devtools tree-shaking details</summary>

environment.ts:
```typescript
import { withDevtools } from '@angular-architects/ngrx-toolkit';

export const environment = {
storeWithDevTools: withDevtools
}
```

environment.prod.ts
```typescript
import { withDevtoolsStub } from '@angular-architects/ngrx-toolkit';

export const environment = {
storeWithDevTools: withDevToolsStub
}
```

Then all you need to do is replace `withDevTools` everywhere in your app with `environment.storeWithDevTools`
e.g.:
```typescript
export const SomeStore = signalStore(
withState({strings: [] as string[] }),
environment.storeWithDevTools('featureName')
);
```

Also make sure you have defined file replacements in angular.json prod configuration:
```json
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
```

</details>


## Redux: `withRedux()`

`withRedux()` bring back the Redux pattern into the Signal Store.
Expand Down
1 change: 1 addition & 0 deletions libs/ngrx-toolkit/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export {
withDevToolsStub,
withDevtools,
patchState,
updateState,
Expand Down
5 changes: 5 additions & 0 deletions libs/ngrx-toolkit/src/lib/with-devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export function reset() {
storeRegistry.set({});
}

/**
* Stub for DevTools integration. Can be used to disable DevTools in production.
*/
export const withDevToolsStub: typeof withDevtools = () => store => store;

/**
* @param name store's name as it should appear in the DevTools
*/
Expand Down

0 comments on commit 4c2baa9

Please sign in to comment.