Skip to content

Commit 8ce9a1a

Browse files
docs: add import statements to doc pages (#162)
1 parent 858feab commit 8ce9a1a

10 files changed

+115
-0
lines changed

docs/docs/create-redux-state.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
title: createReduxState()
33
---
44

5+
```typescript
6+
import { createReduxState } from '@angular-architects/ngrx-toolkit/redux-connector';
7+
```
8+
59
The Redux Connector it is not an extension but turns any `signalStore()` into a Global State Management Slice following the Redux pattern.
610

711
It is available as secondary entry point, i.e. `import { createReduxState } from '@angular-architects/ngrx-toolkit/redux-connector'` and has a dependency to `@ngrx/store`.

docs/docs/with-conditional.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
title: withConditional()
33
---
44

5+
```typescript
6+
import { withConditional } from '@angular-architects/ngrx-toolkit';
7+
```
8+
59
`withConditional` activates a feature based on a given condition.
610

711
## Use Cases
@@ -17,6 +21,8 @@ Otherwise, a type error will occur.
1721
## Usage
1822

1923
```typescript
24+
import { withConditional } from '@angular-architects/ngrx-toolkit';
25+
2026
const withUser = signalStoreFeature(
2127
withState({ id: 1, name: 'Konrad' }),
2228
withHooks((store) => ({

docs/docs/with-data-service.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
title: withDataService()
33
---
44

5+
```typescript
6+
import { withDataService } from '@angular-architects/ngrx-toolkit';
7+
```
8+
59
`withDataService()` allows to connect a Data Service to the store:
610

711
This gives you a store for a CRUD use case:
812

913
```typescript
14+
import { withDataService, withCallState, withUndoRedo } from '@angular-architects/ngrx-toolkit';
15+
1016
export const SimpleFlightBookingStore = signalStore(
1117
{ providedIn: 'root' },
1218
withCallState(),
@@ -86,6 +92,8 @@ export class FlightSearchSimpleComponent {
8692
To avoid naming conflicts, the properties set up by `withDataService` and the connected features can be configured in a typesafe way:
8793

8894
```typescript
95+
import { withDataService, withCallState, withUndoRedo } from '@angular-architects/ngrx-toolkit';
96+
8997
export const FlightBookingStore = signalStore(
9098
{ providedIn: 'root' },
9199
withCallState({

docs/docs/with-devtools.md

+36
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
title: withDevtools()
33
---
44

5+
```typescript
6+
import { withDevtools } from '@angular-architects/ngrx-toolkit';
7+
```
8+
59
Redux Devtools is a powerful browser extension tool, that allows you to inspect every change in your stores. Originally, it was designed for Redux, but it can also be used with the SignalStore. You can download it for Chrome [here](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd).
610

711
To use the Devtools, you need to add the `withDevtools()` extension to your SignalStore:
812

913
```typescript
14+
import { withDevtools } from '@angular-architects/ngrx-toolkit';
15+
1016
export const FlightStore = signalStore(
1117
{ providedIn: 'root' },
1218
withDevtools('flights'), // <-- add this
@@ -27,9 +33,15 @@ The extensions don't activate during app initialization (as it is with `@ngrx/st
2733

2834
## `updateState()` vs `patchState()`
2935

36+
```typescript
37+
import { updateState } from '@angular-architects/ngrx-toolkit';
38+
```
39+
3040
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()`:
3141

3242
```typescript
43+
import { updateState } from '@angular-architects/ngrx-toolkit';
44+
3345
patchState(this.store, { loading: false });
3446

3547
// updateState is a wrapper around patchState and has an action name as second parameter
@@ -38,13 +50,19 @@ updateState(this.store, 'update loading', { loading: false });
3850

3951
## `renameDevtoolsName()`
4052

53+
```typescript
54+
import { renameDevtoolsName } from '@angular-architects/ngrx-toolkit';
55+
```
56+
4157
If multiple instances of a given SignalStore exist, the Devtools will index the names. For example, if you have two `TodoDetail` instances with the name `todo-detail`, the first one will be named `todo-detail` and the second one `todo-detail-1`.
4258

4359
At any time, you can use `renameDevtoolsName()` to change the name of the store in the Devtools.
4460

4561
The following example shows a component, which has a locally provided store and renames it according to the `id` of the `todo` Signal.
4662

4763
```typescript
64+
import { renameDevtoolsName, withDevtools } from '@angular-architects/ngrx-toolkit';
65+
4866
const TodoDetailStore = signalStore(withDevtools('todo-detail'), withState({ id: 1 }));
4967

5068
@Component({
@@ -65,6 +83,10 @@ export class TodoDetailComponent {
6583

6684
## `withGlitchTracking()`
6785

86+
```typescript
87+
import { withGlitchTracking } from '@angular-architects/ngrx-toolkit';
88+
```
89+
6890
It tracks all state changes of the State, including intermediary updates
6991
that are typically suppressed by Angular's glitch-free mechanism.
7092

@@ -73,6 +95,8 @@ This feature is especially useful for debugging.
7395
Example:
7496

7597
```typescript
98+
import { withGlitchTracking, withDevtools } from '@angular-architects/ngrx-toolkit';
99+
76100
const Store = signalStore(
77101
{ providedIn: 'root' },
78102
withState({ count: 0 }),
@@ -96,23 +120,35 @@ It is also possible to mix. So one store could have `withGlitchTracking()` and a
96120

97121
## `withDisabledNameIndices()`
98122

123+
```typescript
124+
import { withDisabledNameIndices } from '@angular-architects/ngrx-toolkit';
125+
```
126+
99127
`withDevtools()` foresees the possibility to add features which extend or modify it. At the moment, `withDisabledNameIndices()` is the only feature available. It disables the automatic indexing of the store names in the Devtools.
100128

101129
If multiple instances exist at the same time, `withDisabledNameIndices()` will throw an error. This is useful if you want to ensure that only one instance of a store is active at a time or that the store name is unique.
102130

103131
You activate per store:
104132

105133
```typescript
134+
import { withDisabledNameIndices, withDevtools } from '@angular-architects/ngrx-toolkit';
135+
106136
const Store = signalStore({ providedIn: 'root' }, withDevtools('flights', withDisabledNameIndices()), withState({ airline: 'Lufthansa' }));
107137
```
108138

109139
## `withMapper()`
110140

141+
```typescript
142+
import { withMapper } from '@angular-architects/ngrx-toolkit';
143+
```
144+
111145
`withMapper()` allows you to define a function that maps the state before it is sent to the Devtools.
112146

113147
Sometimes, it is necessary to map the state before it is sent to the Devtools. For example, you might want to exclude some properties, like passwords or other sensitive data.
114148

115149
```typescript
150+
import { withMapper, withDevtools } from '@angular-architects/ngrx-toolkit';
151+
116152
const initialState = {
117153
id: 1,
118154
email: 'john.list@host.com',

docs/docs/with-feature-factory.md

+10
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
title: withFeatureFactory()
33
---
44

5+
```typescript
6+
import { withFeatureFactory } from '@angular-architects/ngrx-toolkit';
7+
```
8+
59
The `withFeatureFactory()` function allows passing properties, methods, or signals from a SignalStore to a feature. It is an advanced feature, primarily targeted for library authors for SignalStore features.
610

711
Its usage is very simple. It is a function which gets the current store:
812

913
```typescript
14+
import { withFeatureFactory } from '@angular-architects/ngrx-toolkit';
15+
1016
function withSum(a: Signal<number>, b: Signal<number>) {
1117
return signalStoreFeature(
1218
withComputed(() => ({
@@ -103,6 +109,8 @@ function withEntityLoader(load: (id: number) => Promise<Entity>) {
103109
`withFeatureFactory` can now map the existing `load` method to the required one.
104110

105111
```typescript
112+
import { withFeatureFactory } from '@angular-architects/ngrx-toolkit';
113+
106114
const store = signalStore(
107115
withMethods((store) => ({
108116
load(id: number): Observable<Entity> {
@@ -171,6 +179,8 @@ signalStore(
171179
Again, `withFeatureFactory` can solve this issue by replacing the input constraint with a function parameter:
172180

173181
```typescript
182+
import { withFeatureFactory } from '@angular-architects/ngrx-toolkit';
183+
174184
function withEntityLoader<T>(loader: (id: number) => Promise<T>) {
175185
return signalStoreFeature(
176186
withState({

docs/docs/with-immutable-state.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
title: withImmutableState()
33
---
44

5+
```typescript
6+
import { withImmutableState } from '@angular-architects/ngrx-toolkit';
7+
```
8+
59
`withImmutableState` acts like `withState` but protects
610
the state against unintended mutable changes, by throwing
711
a runtime error.
@@ -10,6 +14,8 @@ The protection is not limited to changes within the
1014
SignalStore but also outside of it.
1115

1216
```typescript
17+
import { withImmutableState } from '@angular-architects/ngrx-toolkit';
18+
1319
const initialState = { user: { id: 1, name: 'Konrad' } };
1420

1521
const UserStore = signalStore(
@@ -62,5 +68,7 @@ By default, `withImmutableState` is only active in development mode.
6268
There is a way to enable it in production mode as well:
6369

6470
```typescript
71+
import { withImmutableState } from '@angular-architects/ngrx-toolkit';
72+
6573
const UserStore = signalStore({ providedIn: 'root' }, withImmutableState(initialState, { enableInProduction: true }));
6674
```

docs/docs/with-redux.md

+20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
title: withRedux()
33
---
44

5+
```typescript
6+
import { withRedux } from '@angular-architects/ngrx-toolkit';
7+
```
8+
59
`withRedux()` brings back the Redux pattern into the Signal Store.
610

711
It can be combined with any other extension of the Signal Store.
@@ -17,6 +21,8 @@ There is also a [Redux Connector](./create-redux-state) available, which is a se
1721
Example:
1822

1923
```typescript
24+
import { withRedux } from '@angular-architects/ngrx-toolkit';
25+
2026
export const FlightStore = signalStore(
2127
{ providedIn: 'root' },
2228
withState({ flights: [] as Flight[] }),
@@ -53,13 +59,23 @@ export const FlightStore = signalStore(
5359

5460
## Extracting actions, reducer and effects into separate files
5561

62+
```typescript
63+
import { createReducer } from '@angular-architects/ngrx-toolkit';
64+
```
65+
66+
```typescript
67+
import { createEffects } from '@angular-architects/ngrx-toolkit';
68+
```
69+
5670
`createReducer` and `createEffects` allow you to extract the reducer and effects into separate files.
5771

5872
There is no need for a `createActions` function, because the actions are just an object literal.
5973

6074
Example:
6175

6276
```typescript
77+
import { withRedux, createReducer, createEffects } from '@angular-architects/ngrx-toolkit';
78+
6379
interface FlightState {
6480
flights: Flight[];
6581
effect1: boolean;
@@ -110,6 +126,10 @@ signalStore(
110126

111127
### Configuring the Redux Devtools Extension
112128

129+
```typescript
130+
import { provideDevtoolsConfig } from '@angular-architects/ngrx-toolkit';
131+
```
132+
113133
The `provideDevtoolsConfig` function allows you to configure the Redux DevTools integration for your NgRx SignalStore. This function is essential for setting up the DevTools with custom options. The function only needs to be called once in your appConfig or AppModule.
114134

115135
To use `provideDevtoolsConfig`, you need to import it and call it in your providers array.

docs/docs/with-reset.md

+11
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
title: withReset()
33
---
44

5+
```typescript
6+
import { withReset } from '@angular-architects/ngrx-toolkit';
7+
```
8+
59
`withReset()` adds a method to reset the state of the Signal Store to its initial value. Nothing more to say about it 😅
610

711
Example:
812

913
```typescript
14+
import { withReset } from '@angular-architects/ngrx-toolkit';
15+
1016
const Store = signalStore(
1117
withState({
1218
user: { id: 1, name: 'Konrad' },
@@ -34,12 +40,17 @@ console.log(store.user()); // { id: 1, name: 'Konrad' }
3440

3541
## `setResetState()`
3642

43+
```typescript
44+
import { setResetState } from '@angular-architects/ngrx-toolkit';
45+
```
46+
3747
If you want to set a custom reset state, you can use the `setResetState()` method.
3848

3949
Example:
4050

4151
```typescript
4252
// continue from the previous example
53+
import { setResetState } from '@angular-architects/ngrx-toolkit';
4354

4455
setResetState(store, { user: { id: 3, name: 'Jane' }, address: { city: 'Berlin', zip: '10115' } });
4556
store.changeUser(4, 'Alice');

docs/docs/with-storage-sync.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
title: withStorageSync()
33
---
44

5+
```typescript
6+
import { withStorageSync } from '@angular-architects/ngrx-toolkit';
7+
```
8+
59
`withStorageSync` adds automatic or manual synchronization with Web Storage (`localstorage`/`sessionstorage`).
610

711
:::warning
@@ -11,6 +15,8 @@ As Web Storage only works in browser environments it will fallback to a stub imp
1115
Example:
1216

1317
```typescript
18+
import { withStorageSync } from '@angular-architects/ngrx-toolkit';
19+
1420
const SyncStore = signalStore(
1521
withStorageSync<User>({
1622
key: 'synced', // key used when writing to/reading from storage

docs/docs/with-undo-redo.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
title: withUndoRedo()
33
---
44

5+
```typescript
6+
import { withUndoRedo } from '@angular-architects/ngrx-toolkit';
7+
```
8+
59
`withUndoRedo` adds undo and redo functionality to the store.
610

711
Example:
812

913
```typescript
14+
import { withUndoRedo } from '@angular-architects/ngrx-toolkit';
15+
1016
const SyncStore = signalStore(
1117
withUndoRedo({
1218
maxStackSize: 100, // limit of undo/redo steps - `100` by default

0 commit comments

Comments
 (0)