-
Notifications
You must be signed in to change notification settings - Fork 405
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): action status "PreHandler" #2305
base: master
Are you sure you want to change the base?
Conversation
Before this change, it was not possible to prepare for an action before it was processed by NGXS. This is because the DISPATCHED event is emitted only after the action handlers have been executed, which is unclear from the documentation: ofActionDispatched: This will ONLY grab actions that have just been dispatched Since changing this behavior would break the public API, this update introduces a new event, PreHandler, which allows reacting to an action before any handler is executed.
FYI @markwhitfeld this is the new feature I mentioned earlier :) |
View your CI Pipeline Execution ↗ for commit af4af0e.
☁️ Nx Cloud last updated this comment at |
Code Climate has analyzed commit af4af0e and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 100.0% (50% is the threshold). This pull request will bring the total coverage in the repository to 95.3% (0.0% change). View more on Code Climate. |
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.
Hi @XavierDupessey
Have you thought about implementing this callback through a dedicated plugin?
The Plugin API allows you to intercept each action call before it calls the handlers.
This plugin could expose a BeforeDispatch
stream that is similar to the Actions
stream.
No, I hadn't considered implementing it as a plugin first. But you're right, it's very straightforward using the If you believe there's no need to expose this event in the core, I'm totally fine with going the plugin route instead! 🙂 |
I'll have a chat with the team about it, but for now I think that the plugin route is best. |
Before this change, it was not possible to prepare for an action before it was processed by NGXS.
This is because the DISPATCHED event is emitted only after the action handlers have been executed, which is unclear from the documentation: ofActionDispatched: This will ONLY grab actions that have just been dispatched
Since changing this behavior would break the public API, this update introduces a new event, PreHandler, which allows reacting to an action before any handler is executed.
PR Checklist
Please check if your PR fulfills the following requirements:
Doc will be adapted if the PR is accepted (page to update is https://www.ngxs.io/concepts/actions/action-handlers)
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently, it was not possible to prepare for an action before it was processed by NGXS.
What is the new behavior?
The action PreHandler is emitted before NGXS executes any handler.
Does this PR introduce a breaking change?