-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Lodash: Refactor away from _.times()
#43374
Conversation
Size Change: +25 B (0%) Total Size: 1.24 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.
LGTM, great work @tyxla! 👍
@@ -24,23 +19,23 @@ function Stars( { rating } ) { | |||
stars | |||
) } | |||
> | |||
{ times( fullStarCount, ( i ) => ( | |||
{ Array.from( { length: fullStarCount } ).map( ( _, i ) => ( |
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. Array.from( { length: n } )
is a new one for me; I usually do Array( n ).fill( 0 )
or so, .fill
being there to avoid the empty array issue. I suppose this is more readable. Very interesting.
This will even silently produce an empty array (instead of throwing an exception) for invalid array lengths, such as fractional numbers, thus matching the behaviour of _.times()
. Pretty impressive 👍
What?
This PR removes the
_.times()
usage completely and deprecates the function.Why?
Lodash is known to unnecessarily inflate the bundle size of packages, and in most cases, it can be replaced with native language functionality. See these for more information and rationale:
@wordpress/api-fetch
package haslodash
as a dependency #39495How?
_.times( x, y )
is easily replacible byArray.from( { length: x } ).map( y )
.Testing Instructions