File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
projects/www/src/app/pages/guide/signals Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,35 @@ console.log(firstName()); // logs: 'Eric'
54
54
console .log (lastName ()); // logs: 'Clapton'
55
55
```
56
56
57
+ If the root properties of a state are already of type ` WritableSignal ` , they will be reused, instead of creating new signals.
58
+ This allows an integration of external ` WritableSignal ` s — such as ` linkedSignal ` or ` resource.value ` .
59
+
60
+ ``` ts
61
+ import { linkedSignal } from ' @angular/core' ;
62
+ import { signalState } from ' @ngrx/signals' ;
63
+ import { User } from ' ./user.model' ;
64
+
65
+ const referenceId = signal (1 );
66
+
67
+ const userState = signalState <UserState >({
68
+ user: linkedSignal <User >(() => ({
69
+ id: referenceId (),
70
+ firstName: ' ' ,
71
+ lastName: ' ' ,
72
+ })),
73
+ isAdmin: false ,
74
+ });
75
+
76
+ console .log (userState .user ()); // logs: { id: 1, firstName: '', lastName: '' }
77
+ patchState (userState , {
78
+ user: { id: 2 , firstName: ' Brian' , lastName: ' May' },
79
+ });
80
+ console .log (userState .user ()); // logs: { id: 2, firstName: 'Brian', lastName: 'May' }
81
+
82
+ referenceId .set (3 );
83
+ console .log (userState .user ()); // logs: { id: 3, firstName: '', lastName: '' }
84
+ ```
85
+
57
86
<ngrx-docs-alert type =" help " >
58
87
59
88
For enhanced performance, deeply nested signals are generated lazily and initialized only upon first access.
You can’t perform that action at this time.
0 commit comments