-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat(signals): add signalMethod
#4597
feat(signals): add signalMethod
#4597
Conversation
✅ Deploy Preview for ngrx-io ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
LGTM 👍
I just left some comments on the docs.
Also, do we want to add a section similar to https://deploy-preview-4597--ngrx-io.netlify.app/guide/signals/rxjs-integration#reactive-methods-without-arguments?
We can but then we should also maybe provide a good example. Any ideas? I was thinking about some reset function which is triggered if a const userId = signal(1);
signalStore(
withMethods(store => ({
reset: signalMethod<void>(() => patchState(store, initialState);
})
) |
@rainerhahnekamp that's a good question 😅. Initially I was thinking about a I like the signalStore(
withMethods(store => ({
reset: signalMethod<void>(() => patchState(store, initialState)),
// compared to
reset2: () => patchState(store, initialState),
})
) If we can't think of a good example, then maybe it isn't useful to create a |
If you have const userId = signal(1);
store.reset(userId);
store.reset2(userId); Both will run once, but |
Yes, but that's with an argument. |
Oopsi... then I’m actually running quite short on examples! Then I'll guess if we don't see a need for it, we don't need to mention it in the docs? |
Sounds good to me @rainerhahnekamp , we can always update it later if needed. |
`signalMethod` is a factory function to process side effects on Signals or static values. It is similar to `rxMethod` but does not support RxJS. `signalMethod` follows Angular's pattern of RxJS-less utilities for Signals, like `resource` and `rxResource`. `signalMethod` expects a type and processor function: ```typescript const doubleLogger = signalMethod<number>(value => console.log(value * 2)) const value = signal(1); doubleLogger(value); // tracks value and executes initially and on every change ``` It also supports static values, e.g., `doubleLogger(1)`.
Co-authored-by: Tim Deschryver <[email protected]>
Co-authored-by: Tim Deschryver <[email protected]>
Co-authored-by: Tim Deschryver <[email protected]>
b2c253c
to
9f05e60
Compare
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.
Great work Rainer! 👏
The implementation part looks good to me. 👍 I left suggestions for documentation:
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Marko Stanimirović <[email protected]>
@markostanimirovic, as always also thanks for your thorough review. I've committed all your suggestions and moved the 2 destroying tests to their suite. |
signalMethod
(#4581)signalMethod
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Marko Stanimirović <[email protected]>
Co-authored-by: Marko Stanimirović <[email protected]>
@markostanimirovic I committed all your requested changes except one. I can't figure out what you meant here: #4597 (comment) |
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.
👏👏👏
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.
🚀
signalMethod
is a factory function to process side effects on Signals or static values.It is similar to
rxMethod
but does not support RxJS.signalMethod
follows Angular's pattern of RxJS-less utilities for Signals, likeresource
andrxResource
.signalMethod
expects a type and processor function:It also supports static values, e.g.,
doubleLogger(1)
.This PR also contains the documentation and tests.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Closes #4581
What is the new behavior?
Does this PR introduce a breaking change?