-
Notifications
You must be signed in to change notification settings - Fork 4.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
Move getStablePath function into the wordrpess/url package #35992
Conversation
…dpress/url package.
…dpress/url package (because we've moved normalizePath to the wordpress/url package).
Size Change: +3.67 kB (0%) Total Size: 1.08 MB
ℹ️ View Unchanged
|
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.
Makes sens to me!
Left a potential improvement we could do, but not necessary for this PR.
We will want to also add a entry in the CHANGELOG file too.
// 'b=1&c=2&a=5' | ||
return ( | ||
base + | ||
'?' + | ||
query | ||
// [ 'b=1', 'c=2', 'a=5' ] | ||
.split( '&' ) | ||
// [ [ 'b, '1' ], [ 'c', '2' ], [ 'a', '5' ] ] | ||
.map( ( entry ) => entry.split( '=' ) ) | ||
// [ [ 'a', '5' ], [ 'b, '1' ], [ 'c', '2' ] ] | ||
.sort( ( a, b ) => a[ 0 ].localeCompare( b[ 0 ] ) ) | ||
// [ 'a=5', 'b=1', 'c=2' ] | ||
.map( ( pair ) => pair.join( '=' ) ) | ||
// 'a=5&b=1&c=2' | ||
.join( '&' ) | ||
); |
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.
Now that we don't have to support IE, we can do this instead:
const searchParams = new URLSearchParams( query );
searchParams.sort();
return `${base}?${ searchParams.toString() }`;
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.
That's a good idea. Thank you, @kevin940726 !
I've updated the changelog files in d724344
UPD:
Left a potential improvement we could do, but not necessary for this PR.
I've created an issue for this improvement: #36046
@@ -2,6 +2,10 @@ | |||
|
|||
## Unreleased | |||
|
|||
### Internal |
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.
I don't think we need to add changelog for internal function. They aren't expected to be used by users anyway.
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.
@kevin940726
Excuse me, but I don't understand why we don't have to add such changes to the changelog.
This document states that:
For each pull request, you should always include relevant changes in a "Unreleased" heading at the top of the file. You should add the heading if it doesn't already exist.
Also, it says this:
"Internal" - Changes which do not have an impact on the public interface or behavior of the module (requires a patch version bump).
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.
Huh, I guess that we're just not strictly following this 😅 ? Anyway, this looks fine to me.
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.
I guess that we're just not strictly following this
Yes, it looks like so. 😅
But maybe we should (I am not excluding myself from the list).
Again, thank you for the review!
Description
We have some duplicate code in both
wordpress/api-fetch
andwordpress/edit-navigation
packages.Both of these packages have the
getStablePath
function defined.This PR aims to move
getStablePath
into thewordpress/url
package and rename it tonormalizePath
. Thus, it can be used by bothwordpress/api-fetch
andwordpress/edit-navigation
packages.Fixes #35799.
How has this been tested?
This PR aims to refactor the
getStablePath
function. So, to test this PR, it's enough to verify that there are nonormalizePath
/getStablePath
related errors in the console when you open Navigation Editor.Screenshots
No screenshots are needed.
Types of changes
New feature (refactoring)
Checklist:
*.native.js
files for terms that need renaming or removal).