Skip to content

Commit e14e45c

Browse files
committed
docs: update content
1 parent 20f1398 commit e14e45c

File tree

4 files changed

+53
-72
lines changed

4 files changed

+53
-72
lines changed

projects/www/src/app/pages/guide/component-store/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ Effects are used to perform additional validation and get extra information from
293293
region="updating-state">
294294
295295
```ts
296-
changePageSize(newPageSize: number) {
296+
changePageSize(newPageSize: number) {
297297
this.paginatorStore.changePageSize(newPageSize);
298298
}
299299
nextPage() {

projects/www/src/app/pages/guide/signals/signal-state.md

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -117,34 +117,6 @@ patchState(userState, (state) => ({
117117
patchState(userState, setFirstName('Stevie'), setAdmin());
118118
```
119119

120-
## Using User-Defined Signals
121-
122-
The `signalState` function supports integrating user-defined `WritableSignal` instances as part of the state.
123-
124-
If a root state property is a `WritableSignal`, its value becomes an integral part of the state.
125-
The SignalState instance and the original signal remain synchronized - updating one will immediately reflect in the other.
126-
127-
```ts
128-
const name = signal('Jimi Hendrix');
129-
const userState = signalState({
130-
// 👇 Providing an external signal as part of the initial state.
131-
name,
132-
isAdmin: false,
133-
});
134-
135-
console.log(userState.name()); // logs: Jimi Hendrix
136-
137-
// Updating the external signal
138-
name.set('Brian May');
139-
// reflects the value in the SignalState instance.
140-
console.log(userState.name()); // logs: Brian May
141-
142-
// Updating the SignalState instance
143-
patchState(userState, { name: 'Eric Clapton' });
144-
// reflects the value in the external signal.
145-
console.log(name()); // logs: Eric Clapton
146-
```
147-
148120
## Usage
149121

150122
### Example 1: SignalState in a Component

projects/www/src/app/pages/guide/signals/signal-store/index.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,6 @@ The `BookSearchStore` instance will contain the following properties:
4949

5050
<ngrx-docs-alert type="help">
5151

52-
In addition to plain values, the `withState` feature also accepts user-defined `WritableSignal` instances as part of the state.
53-
In this case, the SignalStore's state and the original signal remain synchronized - updating one will immediately reflect in the other.
54-
55-
```ts
56-
import { signalStore, withState } from '@ngrx/signals';
57-
import { Book } from './book';
58-
59-
const books = signal<Book[]>([]);
60-
61-
const BookSearchStore = signalStore(
62-
withState({
63-
// 👇 Providing an external signal as part of the initial state.
64-
books,
65-
isLoading: false,
66-
})
67-
);
68-
```
69-
70-
</ngrx-docs-alert>
71-
72-
<ngrx-docs-alert type="help">
73-
7452
The `withState` feature also has a signature that takes the initial state factory as an input argument.
7553
The factory is executed within the injection context, allowing initial state to be obtained from a service or injection token.
7654

projects/www/src/app/pages/guide/signals/signal-store/linked-state.md

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,71 @@
11
# Linked State
22

3-
The `withLinkedState` feature enables the creation of state slices that depend on other parts of the state. It supports both implicit and explicit linking.
4-
5-
In the context of the SignalStore, `withLinkedState()` serves as the equivalent to Angular's `linkedSignal()`.
6-
7-
Linked state can be added to the store using the `withLinkedState()` feature. This feature accepts a factory function as an input argument, which is executed within the injection context. The factory should return a dictionary containing:
8-
9-
- Functions that return values, which the SignalStore wraps automatically into a `linkedSignal()`, or
10-
- `WritableSignal`, which the user can create with `linkedSignal()`.
3+
The `withLinkedState` feature enables the creation of state slices that depend on other signals.
4+
This feature accepts a factory function as an input argument, which is executed within the injection context.
5+
The factory should return a dictionary containing linked state slices, defined as either computation functions or `WritableSignal` instances.
6+
These linked state slices become an integral part of the SignalStore's state and are treated the same as regular state slices - `DeepSignal`s are created for each of them, and they can be updated using `patchState`.
117

128
## Implicit Linking
139

14-
The following example shows the implicit notation, where a function returns a value. That function is wrapped into a `linkedSignal()`, which means it is tracked, and if one of the tracked Signals changes, the function is re-executed synchronously.
10+
When a computation function is provided, the SignalStore wraps it in a `linkedSignal()`.
11+
As a result, the linked state slice is updated automatically whenever any of its dependent signals change.
1512

16-
<ngrx-code-example header="options-store.ts">
13+
<code-tabs linenums="true">
14+
<code-pane header="options-store.ts">
1715

1816
```ts
19-
import {
20-
signalStore,
21-
withLinkedState,
22-
withState,
23-
} from '@ngrx/signals';
17+
import { patchState, signalStore, withLinkedState, withState } from '@ngrx/signals';
2418

2519
export const OptionsStore = signalStore(
26-
withState({ options: [1, 2, 3] }),
27-
withLinkedState(({ options }) => ({
28-
selectedOption: () => options()[0] ?? undefined,
29-
}))
20+
withState({ options: [1, 2, 3] }),
21+
withLinkedState(({ options }) => ({
22+
// 👇 Defining a linked state slice.
23+
selectedOption: () => options()[0] ?? undefined,
24+
})),
25+
withMethods((store) => ({
26+
setOptions(options: number[]): void {
27+
patchState(store, { options });
28+
},
29+
setSelectedOption(selectedOption: number): void {
30+
// 👇 Updating a linked state slice.
31+
patchState(store, { selectedOption });
32+
},
33+
}),
3034
);
3135
```
3236
33-
</ngrx-code-example>
37+
</code-pane>
38+
39+
<code-pane header="option-list.ts">
40+
41+
```ts
42+
@Component({
43+
// ... other metadata
44+
providers: [OptionsStore],
45+
})
46+
export class OptionList {
47+
readonly store = inject(OptionsStore);
48+
49+
constructor() {
50+
console.log(this.store.selectedOption()); // logs: 1
51+
52+
this.store.setSelectedOption(2);
53+
console.log(this.store.selectedOption()); // logs: 2
54+
55+
this.store.setOptions([4, 5, 6]);
56+
console.log(this.store.selectedOption()); // logs: 4
57+
}
58+
}
59+
```
60+
61+
</code-pane>
62+
</code-tabs>
3463
3564
## Explicit Linking
3665
37-
The explicit notation requires users to execute `linkedSignal()` manually; however, it offers the advantage of using the more powerful version of `linkedSignal()`, which includes the `source` and `computation` options.
66+
The `withLinkedState` feature also supports providing `WritableSignal` instances as linked state slices.
67+
This can include signals created using `linkedSignal()` with `source` and `computation` options, as well as any other `WritableSignal` instances.
68+
In both cases, the SignalStore and the original signal remain fully synchronized - updating one immediately reflects in the other.
3869
3970
<ngrx-code-example header="options-store.ts">
4071

0 commit comments

Comments
 (0)