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

[Pagination] Leverage @default over default values #19966

Merged
merged 3 commits into from
Mar 4, 2020

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Mar 3, 2020

Using runtime for documentation can be quite confusing. Let's solve docs concerns with jsdoc instead. Both approaches can just as easily become outdated. But the new one doesn't add noise to the implementation.

yarn docs:api will throw if you use a default value and @default in the propTypes even if they have the same value e.g.

function Component(props) {
  const { page = 1 } = props; 
} 
Component.propTypes = { 
  /**
   * @default 1
   */
  page: PropTypes.number 
};

will throw:

Error parsing src for /home/eps1lon/Development/projects/mui/fork/packages/material-ui-lab/src/Pagination/Pagination.js
error building docs for /home/eps1lon/Development/projects/mui/fork/packages/material-ui-lab/src/Pagination/Pagination.js
Error: Can't have JavaScript default value and jsdoc @defaultValue in prop 'boundaryCount'. Remove the @defaultValue if you need the JavaScript default value at runtime.

@eps1lon eps1lon added docs Improvements or additions to the documentation component: pagination This is the name of the generic UI component, not the React module! labels Mar 3, 2020
@mui-pr-bot
Copy link

mui-pr-bot commented Mar 3, 2020

No bundle size changes comparing 41fe2e2...e242671

Generated by 🚫 dangerJS against e242671

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

Interesting! It could potentially be used for a couple of other components, the Autocomplete for instance :).

The only point that I wonder about is how does this "direction" affects moving the descriptions of the prop-types in TypeSript?

packages/material-ui-lab/src/Pagination/usePagination.js Outdated Show resolved Hide resolved
@eps1lon
Copy link
Member Author

eps1lon commented Mar 3, 2020

The only point that I wonder about is how does this "direction" affects moving the descriptions of the prop-types in TypeSript?

We probably want to do this at some point anyway. Then we need to be more careful with throwing an error if we find both (probably just verify they're equal). In any case: the default value in the typescript types would be a nice to have.

@eps1lon eps1lon force-pushed the chore/Pagination/no-runtime-for-docs branch from 35011cb to e242671 Compare March 4, 2020 15:05
@eps1lon eps1lon merged commit 89c0ed4 into mui:master Mar 4, 2020
@eps1lon eps1lon deleted the chore/Pagination/no-runtime-for-docs branch March 4, 2020 21:39
EsoterikStare pushed a commit to EsoterikStare/material-ui that referenced this pull request Mar 30, 2020
@eps1lon
Copy link
Member Author

eps1lon commented Sep 2, 2020

Will be reverted in #22447. The problem is that it's not accurate. The default value in the component for boundaryCount is not 1. Only in usePagination.

@mbrookes
Copy link
Member

mbrookes commented Sep 2, 2020

The only point that I wonder about is how does this "direction" affects moving the descriptions of the prop-types in TypeSript?

OT, but speaking of direction, am I the only one that feels that the current direction for sharing prop descriptions is "backwards"? I routinely edit the component prop descriptions first, so then have to sync them manually, since the script assumes that the type definitions is the singe source of truth. Class names go in the opposite direction.

@eps1lon
Copy link
Member Author

eps1lon commented Sep 2, 2020

I routinely edit the component prop descriptions first, so then have to sync them manually, since the script assumes that the type definitions is the singe source of truth. Class names go in the opposite direction.

Purely technical decision.

TypeScript declarations have very different shapes to accomodate certain patterns. Figuring out where to put the description is incredibly hard. .propTypes on the other hand have a single pattern that we can easily generate with babel.

Same for classes: This would be slightly easier to figure out where the description goes in the JS file but would still need flow analysis. In TypeScript it's currently a single pattern: A type property with name classes.

Since this is all driven by "routine" I don't think it's worth putting time into it. Sure, a single file would be better (though I'd personally never do this since it discourages extensive documentation). But I feel like we have pretty clear messaging what went wrong with documentation and how to fix it.

@mbrookes
Copy link
Member

mbrookes commented Sep 2, 2020

Figuring out where to put the description is incredibly hard.

Makes sense, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pagination This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants