-
-
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
perf(router-store): optimize selectQueryParams, selectQueryParam and selectFragment selectors #2764
perf(router-store): optimize selectQueryParams, selectQueryParam and selectFragment selectors #2764
Conversation
Preview docs changes for 37e4a91 at https://previews.ngrx.io/pr2764-37e4a919/ |
3136bef
to
1c41ab5
Compare
@alex-okrushko @brandonroberts @timdeschryver
|
@markostanimirovic you have to use the |
1c41ab5
to
0db73b8
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.
Out of curiosity, I see this was first a perf change but how does this optimize the router selectors?
Doesn't the Optional Chaining operator compile to the same code?
Since this is a refactor, I would also revert the changes made to the spec
to be sure we didn't break something. Or perhaps create a second test case for the root with the added fragment and params?
@timdeschryver Optimized are three selectors: About the breaking changes: this should not be a breaking change with Angular router, because fragment and query parameters are the same on root and any other child router tree node. |
I can add tests with |
My bad, I didn't read the description 😅. But this change would also mean that the behavior is different (root vs current route), which you also pointed out. So imho, we should either mark this as a breaking change or leave the implementation as is and create root selectors.
My comment about the spec was that originally it was verifying the child route, while it now validates the root route. |
Sure, let's wait for the opinion of others, and when the final decision is made, I'll fix this PR :) |
So it is a breaking change, right?
Optional chaining actually increases the generated code size. Unless we are reducing both sources code size AND generated code size, I wouldn't suggest to change it. |
Anyway, I can mark this PR as breaking change and change its title to
Okay, I will revert optional chaining 👍 |
@markostanimirovic What's left on this PR? Removal of the optional chaining? |
0db73b8
to
cb9062f
Compare
Tim commented:
And I wanted to hear other thoughts on this and update this PR accordingly 🙂 My opinion is that we don't need new selectors for selecting fragment and query params from root, because with Angular router and default serializer Btw, optional chaining is removed now 🙂 |
I don't think we need new selectors either, but this shouldn't be a breaking change functionally because they are equivalent as you stated. I'd still mark it as a breaking change just so people are aware of it. |
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.
Changes LGTM. Just needs breaking changes to be added to commit message when merging
We should also add a note to the migration docs |
cb9062f
to
4c23651
Compare
…selectFragment selectors
4c23651
to
37e4a91
Compare
@brandonroberts @timdeschryver |
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.
Thanks for adding it to the migration guide
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?
selectQueryParams
- returns query params from the last router state nodeselectQueryParam
- returns a query param from the last router state nodeselectFragment
- returns the fragment from the last router state nodeWhat is the new behavior?
Optional chaining is introduced for all selectors.
selectQueryParams
- returns query params fromrouterState.root
selectQueryParam
- returns a query param fromrouterState.root
selectFragment
- returns the fragment fromrouterState.root
Does this PR introduce a breaking change?
Actually, this can be a breaking change in test files (for
selectQueryParams
,selectQueryParam
andselectFragment
selectors) if mock router state is defined in the wrong way. But when it is used with Angular router, there are no breaking changes.