You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a reactive method is called with an observable, the reactive chain is executed every time the observable emits a new value.
96
127
97
128
```ts
@@ -268,7 +299,7 @@ export class Numbers implements OnInit {
268
299
269
300
<ngrx-docs-alerttype="inform">
270
301
271
-
If the injector is not provided when calling the reactive method with a signal or observable outside the injection context, a warning message about a potential memory leak is displayed in development mode.
302
+
If the injector is not provided when calling the reactive method with a reactive computation or observable outside the injection context, a warning message about a potential memory leak is displayed in development mode.
Copy file name to clipboardExpand all lines: projects/www/src/app/pages/guide/signals/signal-method.md
+29-5Lines changed: 29 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# SignalMethod
2
2
3
-
`signalMethod` is a standalone factory function used for managing side effects with Angular signals. It accepts a callback and returns a processor function that can handle either a static value or a signal. The input type can be specified using a generic type argument:
3
+
`signalMethod` is a standalone factory function used for managing side effects with Angular signals. It accepts a callback and returns a processor function that can handle either a static value or a reactive computation, i.e. either a Signal or a function, which will be tracked automatically. The input type can be specified using a generic type argument:
4
4
5
5
<ngrx-code-example>
6
6
@@ -13,7 +13,7 @@ import { signalMethod } from '@ngrx/signals';
`logDoubledNumber` can be called with a static value of type `number`, or a Signal of type `number`:
26
+
`logDoubledNumber` can be called with a static value of type `number`, or a reactive computation of type `number`. Since a Signal is a function returning a value, it is also a reactive computation.
27
27
28
28
```ts
29
29
@Component({
@@ -49,6 +49,30 @@ export class Numbers {
49
49
}
50
50
```
51
51
52
+
Finally, a reactive computation example shows an automaticaly tracked computation, built from multiple Signals.
`signalMethod` uses an `effect` internally to track the Signal changes.
@@ -184,9 +208,9 @@ export class Numbers {
184
208
185
209
However, `signalMethod` offers three distinctive advantages over `effect`:
186
210
187
-
-**Flexible Input**: The input argument can be a static value, not just a signal. Additionally, the processor function can be called multiple times with different inputs.
211
+
-**Flexible Input**: The input argument can be a static value, not just a reactive computation. Additionally, the processor function can be called multiple times with different inputs.
188
212
-**No Injection Context Required**: Unlike an `effect`, which requires an injection context or an Injector, `signalMethod`'s "processor function" can be called without an injection context.
189
-
-**Explicit Tracking**: Only the Signal of the parameter is tracked, while Signals within the "processor function" stay untracked.
213
+
-**Explicit Tracking**: Only the reactive computation of the parameter is tracked, while Signals within the "processor function" stay untracked.
0 commit comments