Skip to content
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

Merged
merged 3 commits into from Sep 27, 2018

Conversation

alexzherdev
Copy link
Contributor

No description provided.

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)));
Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh 🤦‍♂️

}

const defaults = component.defaultProps || {};
const newDefaultProps = defaultProps.reduce((acc, prop) => {
Copy link
Member

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.

@alexzherdev alexzherdev force-pushed the default-props-detection branch 2 times, most recently from 3f41753 to ce0b2d6 Compare September 9, 2018 01:23
@alexzherdev
Copy link
Contributor Author

alexzherdev commented Sep 20, 2018

@ljharb FYI I have a final refactoring ready but blocked by this, which is to extract isRequired detection from default-props-match-prop-types and require-default-props and make it part of the propTypes detection.
This will be a huge win since this is what will enable these two rules to migrate to the common detection (that piece is also ready).


if (!isPropType && !isDefaultProp) {
if (!isPropType) {
Copy link
Member

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?

Copy link
Contributor Author

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 😄

Copy link
Member

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.

@ljharb
Copy link
Member

ljharb commented Sep 21, 2018

Will merge later today if no objections.

@alexzherdev
Copy link
Contributor Author

Any concerns here?

This was referenced Jan 4, 2019
@ghost ghost mentioned this pull request Jan 12, 2019
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants