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

Infer displayName from function/class/variable name #30

Open
iamdustan opened this issue Oct 14, 2015 · 15 comments
Open

Infer displayName from function/class/variable name #30

iamdustan opened this issue Oct 14, 2015 · 15 comments

Comments

@iamdustan
Copy link
Contributor

Is there a reason this wasn’t already included? Having a displayName with each description would be beneficial for tools that are using docgen without having to re-read the js file to detect the display name again.

This wasn’t that big of a deal with React.createClass or class extends React.Component since those are pretty limited call sites, but the stateless function components can get a bit gnarly in trying to infer their display names. The detection for these are already pretty solid in the #28 branch.

@fkling
Copy link
Member

fkling commented Oct 14, 2015

You mean why it isn't listed in the README? Probably just an oversight from my side.

@iamdustan
Copy link
Contributor Author

wait. does the displayName already appear in there?

@iamdustan
Copy link
Contributor Author

I don’t think it does... this is the result of console.logging

docgen.parse(fs.readFileSync('./my-component.js'))
{ description: '@private',
  props:
   { to: { type: [Object], required: true, description: '' },
     name: { type: [Object], required: true, description: '' } } }

@fkling
Copy link
Member

fkling commented Oct 14, 2015

@fkling
Copy link
Member

fkling commented Oct 30, 2015

I can't repro this btw. The displayName shows up in the result. What does your ./my-component.js look like?

@iamdustan
Copy link
Contributor Author

Hmm..

so I have stateless components not getting a displayName as well as

import React, {PropTypes, Component} from 'react';
class Tabs extends Component {
  ....
}

export default Tabs;

@fkling
Copy link
Member

fkling commented Oct 30, 2015

Oh, the displayName handler only looks for explicit displayName properties. You want it to also return the inferred name from the class or function name, right?

@iamdustan
Copy link
Contributor Author

👍

...does babel still follow that approach for displayName handling?

@mik01aj
Copy link

mik01aj commented Oct 30, 2015

@fkling, yes! (I know the question wasn't to me, but I'd love to have it this way :))

@fkling
Copy link
Member

fkling commented Oct 30, 2015

I don't know, will have to look into this. Seems reasonable to me though. PRs are also welcome ;)

@fkling fkling changed the title include displayName in docs Infer displayName from function/class/variable name Oct 30, 2015
@iamdustan
Copy link
Contributor Author

I vote @mik01aj for those one :)

@AlanFoster
Copy link

Babel will generate the display name for you when it is not supplied explicitly.

👍 to implementing a similar inferrance rule to react-docgen

@AlanFoster
Copy link

@iamdustan Would this be something that is feasible to implement?

@mik01aj
Copy link

mik01aj commented Nov 28, 2015

Maybe you could just use this plugin: https://github.com/gajus/babel-plugin-react-display-name

@NogsMPLS
Copy link
Contributor

NogsMPLS commented Mar 1, 2016

I would love for react-docgen to be able to infer the name of a component based on the Component.name.

Babel only creates a displayName for the .createClass() convention, not for the es6 classes or stateless functional components.

I'll dig around react-docgen today and see if I can figure out a PR that might accomplish this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants