Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

chore: simplify getUnhandledProps() & getElementType()#2003

Merged
layershifter merged 2 commits intomasterfrom
chore/simplify-element-functions
Oct 3, 2019
Merged

chore: simplify getUnhandledProps() & getElementType()#2003
layershifter merged 2 commits intomasterfrom
chore/simplify-element-functions

Conversation

@layershifter
Copy link
Member

@layershifter layershifter commented Oct 3, 2019

Based on findings from #1355.

This PR simplifies our getUnhandledProps() and getElementType() helper functions that makes them more reusable.

I also moved them to @stardust-ui/react-bindings and improved types on them. Adds a missing UT for getElementType().

@layershifter layershifter force-pushed the chore/simplify-element-functions branch from 99f4793 to 7a52ca0 Compare October 3, 2019 13:41
@codecov
Copy link

codecov bot commented Oct 3, 2019

Codecov Report

Merging #2003 into master will increase coverage by 6.72%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2003      +/-   ##
==========================================
+ Coverage   70.29%   77.01%   +6.72%     
==========================================
  Files         894      158     -736     
  Lines        7863     5456    -2407     
  Branches     2304     1578     -726     
==========================================
- Hits         5527     4202    -1325     
+ Misses       2323     1241    -1082     
  Partials       13       13
Impacted Files Coverage Δ
packages/react/src/lib/createComponent.ts 95% <ø> (ø)
packages/react/src/lib/UIComponent.tsx 82.35% <ø> (ø) ⬆️
...ackages/react-bindings/src/utils/getElementType.ts 100% <100%> (ø)
.../src/lib/accessibility/FocusZone/AutoFocusZone.tsx 100% <100%> (ø) ⬆️
...eact/src/lib/accessibility/FocusZone/FocusZone.tsx 89.27% <100%> (ø) ⬆️
packages/react/src/lib/renderComponent.tsx 84.05% <100%> (ø) ⬆️
...ages/react-bindings/src/utils/getUnhandledProps.ts 100% <100%> (ø)
.../src/lib/accessibility/FocusZone/FocusTrapZone.tsx 71.71% <100%> (ø) ⬆️
...s/components/RadioGroup/radioGroupItemVariables.ts
...mponents/Icon/svg/ProcessedIcons/icons-zoom-in.tsx
... and 735 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6919580...6904143. Read the comment docs.

@layershifter layershifter force-pushed the chore/simplify-element-functions branch from 7a52ca0 to 6af3aed Compare October 3, 2019 13:45
@vercel vercel bot temporarily deployed to staging October 3, 2019 13:45 Inactive
@DustyTheBot
Copy link
Collaborator

Warnings
⚠️ There are no updates provided to CHANGELOG. Ensure there are no publicly visible changes introduced by this PR.
⚠️ New package.json added: packages/react-bindings/package.json. Make sure you have approval before merging!
⚠️ Package (or peer) dependencies changed. Make sure you have approval before merging!

Changed dependencies are detected.

Changed dependencies in packages/react/package.json

package before after
@stardust-ui/react-bindings - ^0.39.0

Generated by 🚫 dangerJS

// ----------------------------------------
// user defined "as" element type

if (props.as && props.as !== defaultProps.as) return props.as
Copy link
Member Author

Choose a reason for hiding this comment

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

After #1396 there is no sense in this condition.
We want to use props.as or div. In the case when props.as is not defined it will come from defaultProps.as, it's handled by React.

)

const unhandledProps = getUnhandledProps({ handledProps }, props)
const unhandledProps = getUnhandledProps(handledProps, props)
Copy link
Member Author

Choose a reason for hiding this comment

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

It was strange to pass handledProps in object when we can just pass them.

}

static handledProps = _.keys(AutoFocusZone.propTypes)
static handledProps = _.keys(AutoFocusZone.propTypes) as any
Copy link
Member Author

Choose a reason for hiding this comment

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

💣

_.keys() and Object.keys() returns string[] in TS:

image

So type cast is required is there as typings for getUnhandledProps() are more strict.

@layershifter layershifter merged commit f988f34 into master Oct 3, 2019
@layershifter layershifter deleted the chore/simplify-element-functions branch October 3, 2019 14:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants