-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Extract defaultProps detection #1942
Extract defaultProps detection #1942
Conversation
48e4be0
to
b588947
Compare
lib/util/Components.js
Outdated
const allKeys = new Set(Object.keys(detectionInstructions).concat(Object.keys(propTypesInstructions))); | ||
const defaultPropsInstructions = defaultProps(context, components, utils); | ||
const allKeys = new Set(Object.keys(detectionInstructions).concat(Object.keys(propTypesInstructions)) | ||
.concat(Object.keys(defaultPropsInstructions))); |
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 doesn't need to be two concat calls, it can be arr1.concat(arr2, arr3)
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.
Oh 🤦♂️
lib/util/defaultProps.js
Outdated
} | ||
|
||
const defaults = component.defaultProps || {}; | ||
const newDefaultProps = defaultProps.reduce((acc, prop) => { |
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.
let's use the object.fromentries
package here.
b588947
to
d50df15
Compare
3f41753
to
ce0b2d6
Compare
ce0b2d6
to
b81e19a
Compare
@ljharb FYI I have a final refactoring ready but blocked by this, which is to extract |
|
||
if (!isPropType && !isDefaultProp) { | ||
if (!isPropType) { |
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'm a bit confused why the previous propTypes refactor didn't remove isPropType
, but this defaultProps refactor is able to remove isDefaultProp
. can you elaborate?
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.
Sure.
The first extraction was based on two other rules that had the most comprehensive detection functionality. However, isRequired
detection, which is necessary for the two rules in this current PR, was not part of it. I could have added it there, but that would have blown up an already big PR.
But it is coming in the follow-up PR I mentioned above. I just didn’t want to combine it with this one, again, to keep them focused and manageable in size.
See alexzherdev@572e332 and alexzherdev@8add5de for an exclusive peek 😄
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.
ah ok, gotcha. so all the isPropType stuff will be able to be removed in a followup.
Will merge later today if no objections. |
Any concerns here? |
No description provided.