-
-
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(store): enable dispatching actions on signal changes #4600
feat(store): enable dispatching actions on signal changes #4600
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. |
f70110f
to
dc049ef
Compare
dc049ef
to
58da96d
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.
Nice!
I left some comments for the syntax in the docs.
Thanks @timdeschryver, I've applied all your changes |
I had to rename the type Previously, store.dispatch(loadBook); // 👎
store.dispatch(loadBook({id: 1})); // 👍 As the name says, |
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.
🚀
dc95b5e
to
31fdb74
Compare
Functions that return actions, with property values derived from signals, can now also be dispatched. ```typescript class BookComponent { bookId = input.required<number>(); store = inject(Store); constructor() { this.store.dispatch(() => loadBook({ id: this.bookId() })); } } ``` `dispatch` executes initially and every time the `bookId` changes. If `dispatch` is called within an injection context, the signal is tracked until the context is destroyed. When `dispatch` is called outside a component's injection context, the signal is tracked globally throughout the application's lifecycle. By default, the injection context of the caller is used. If the call happens outside an injection context, the Store will use its own injection context, which is usually the root injector. It is also possible to provide a custom injector as the second parameter: ```typescript this.store.dispatch( () => loadBook({ id: this.bookId() }), { injector: this.injector } ); ```
31fdb74
to
2777038
Compare
Branch has been rebased and commits have been squashed with a meaningful commit message. |
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.
Nice work and review! 🤜🤛
Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com>
Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com>
A type of Signal can be passed to dispatch:
The benefit is that users no longer need to use an effect to track the Signal. The Store handles this internally.
If
dispatch
receives aSignal
it returns anEffectRef
, allowing manual destruction.By default, the injection context of the caller is used. If the call happens outside an injection context, the Store will use its own injection context, which is usually the root injector.
It is also possible to provide a custom injector as the second parameter:
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Users need to manually track Signals via
effect
Closes #4537
What is the new behavior?
Does this PR introduce a breaking change?