-
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
refactor(store): add action registry #2224
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit ddbed56. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 4 targetsSent with 💌 from NxCloud. |
@ngxs/devtools-plugin
@ngxs/form-plugin
@ngxs/hmr-plugin
@ngxs/router-plugin
@ngxs/storage-plugin
@ngxs/store
@ngxs/websocket-plugin
commit: |
BundleMonFiles updated (1)
Unchanged files (5)
Total files change +152B +0.12% Groups updated (2)
Final result: ✅ View report in BundleMon website ➡️ |
BundleMon (NGXS Plugins)Unchanged files (9)
No change in files bundle size Unchanged groups (1)
Final result: ✅ View report in BundleMon website ➡️ |
BundleMon (Integration Projects)Files updated (3)
Total files change +158B +0.07% Final result: ✅ View report in BundleMon website ➡️ |
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 first step of the refactoring, but see my comments for the change in the handlers.
e84ace2
to
004e1f1
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.
Please see comments in this review and the suggested code changes from the previous review.
}; | ||
} | ||
|
||
private _createActionHandler(actionMeta: InvokableActionHandlerMetaData) { |
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.
As mentioned in the second comment of my previous review, the creation of the handler which in turn creates the state context, should stay outside of the action registry (in the StateFactory, for now).
Also the result handling logic should remain where it was in the StateFactory.
interface InvokableActionHandlerMetaData extends ɵActionHandlerMetaData { | ||
path: string; | ||
instance: any; | ||
} |
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.
This data structure should no longer be needed for the registry.
The registry should be super simple, only storing the handler functions, constructed and provided by the StateFactory.
The place in the StateFactory where the handler is created should contain enough access from its closure to be able to do all that it needs.
b30d523
to
891588f
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!!!!
Code Climate has analyzed commit ddbed56 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 96.4% (50% is the threshold). This pull request will bring the total coverage in the repository to 95.3% (-0.1% change). View more on Code Climate. |
@arturovt |
I would first remove Since states are decorated with |
Thanks for the suggestions.
Basically this type of injector usage instead of global static injector could fix the mentioned SSR issue? What do you think about the operation caching used in the Is it ok to use hydrateActionMetasMap() in the decorator or could there be some better/simpler way to register the handlers? |
I think it might be better to find a way to register actions without relying on internal APIs, which are likely to change in the future. It seems that the |
@arturovt thank you for your insights. |
This adds a new internal construct, called the
ActionRegistry
.The
ActionRegistry
facilitates the registration, and recall, of all handlers associated with an action type.The default handler registered for each
@Action
within a state is now responsible for handling the return value of the user's handler within the state and the cancellation logic for the handler.