-
-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(signals): allow auto-tracking function for signalMethod and `r…
#4996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for ngrx-io ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for ngrx-site-v19 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
modules/signals/src/signal-method.ts
Outdated
| config?: { injector?: Injector } | ||
| ): EffectRef => { | ||
| if (isSignal(input)) { | ||
| if (typeof input !== 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched the if condition to eliminate the possibility of a function in the else condition.
With Input | (() => Input) and a `typeof input === 'function', TypeScript would not narrow done the type union.
| The `rxMethod` is a standalone factory function designed for managing side effects by utilizing RxJS APIs. | ||
| It takes a chain of RxJS operators as input and returns a reactive method. | ||
| The reactive method can accept a static value, signal, or observable as an input argument. | ||
| The reactive method can accept a static value, a reactive computation (like a Signal), or observable as an input argument. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am using the term "reactive computation" instead of auto-tracking functions because that's what the Angular team calls it in linkedSignal.
25e40aa to
3fd0f9f
Compare
3fd0f9f to
6074704
Compare
| # SignalMethod | ||
|
|
||
| `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: | ||
| `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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid explaining multiple times that the Signal is compatible with a computation function, wdyt about mentioning a computation function in addition to Signal? (the same comment for other sections where this was changed)
| `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: | |
| `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, a signal, or a computation function. The input type can be specified using a generic type argument: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean I should also remove the example then? Otherwise, I don't see so many places where the docs become easier.
Should we really call it "computation function"? I used "reactive computation", because that's the offical Angular term: https://angular.dev/api/core/linkedSignal.
We could just say "reactive computation" without explanation, but I doubt that most people know what that is...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, I was curious, and it turns out both names are used in varying contexts
https://github.com/search?q=repo%3Aangular%2Fangular+%22reactive+function%22&type=code
https://github.com/search?q=repo%3Aangular%2Fangular+%22reactive+computation%22&type=code
"reactive function" in form/effect/httpResource related stuff, and "reactive computation" in linkedSignal, one resource doc, and a couple primitive file/docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's called differently depending on the API. The input argument of computed is named computation, and it's a function, so I think 'computation function' should be clear enough.
We could just say "reactive computation" without explanation, but I doubt that most people know what that is...
@rainerhahnekamp Agree. I'd keep mentioning signals for clarity.
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Tim Deschryver <[email protected]>
Co-authored-by: Tim Deschryver <[email protected]>
Co-authored-by: Tim Deschryver <[email protected]>
Co-authored-by: Tim Deschryver <[email protected]>
Align signalMethod and rxMethod with Angular’s resource/linkedSignal pattern so callers can pass a lazy () => T instead of creating an intermediate computed signal.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Closes #4986
What is the new behavior?
Does this PR introduce a breaking change?