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

Show real sources instead of "compiled" source with HoC #938

Closed
shilman opened this issue Apr 22, 2017 · 13 comments
Closed

Show real sources instead of "compiled" source with HoC #938

shilman opened this issue Apr 22, 2017 · 13 comments

Comments

@shilman
Copy link
Member

shilman commented Apr 22, 2017

Issue by tleunen
Friday Sep 16, 2016 at 13:49 GMT
Originally opened as storybook-eol/react-storybook-addon-info#73


At first, I thought the plugin was showing the real sources of a story (the exact code that a story contains), but in fact it's showing the sources from the used components, or compiled sources.

Lets say I have this code and this story:

import MyComp from '../MyComp';

storiesOf('MyComp', module)
.addWithInfo(
    'Default MyComp',
    () => (
        <MyComp />
    ),
    { inline: true, propTables: false }
);


//and MyComp.js, something like:
function enhance(Component) {
  return class EnhanceComp extends React.Component {
    render() {
      return <Component>super enhanced</Component>
    }
  };
}


const MyComp = ({children}) => {
    return <div>My {children} Component</div>
};
export default enhance(MyComp);

but if MyComp is actually something using HoC, the rendering won't be

<MyComp /> but <EnhanceComp />

It would be best to keep showing MyComp instead because that's what users should use.

@shilman
Copy link
Member Author

shilman commented Apr 22, 2017

Comment by dimaip
Monday Sep 19, 2016 at 13:36 GMT


Even worse, in my case it may turn into something like this:

<StoryWrapper>
<Themed Button>
The Button
</Themed Button>
</StoryWrapper>

So it would also be good to specify the exact component, the way it works with propTables.
Related to #44

@shilman
Copy link
Member Author

shilman commented Apr 22, 2017

Comment by tleunen
Thursday Sep 22, 2016 at 12:54 GMT


@dimaip There's an easy way to fix the issue, what I've been using now for these components is something like:

import RealComponent from '../';

const MyComponent = props => <RealComponent {...props}>{props.children}</RealComponent>;

// then just use `MyComponent`

@shilman
Copy link
Member Author

shilman commented Apr 22, 2017

Comment by gnarf
Friday Oct 21, 2016 at 17:24 GMT


You can also use displayName on the class which is what the react debugger / this addon will use to "name" a class:

//and MyComp.js, something like:
function enhance(Component) {
  class EnhanceComp extends React.Component {
    render() {
      return <Component>super enhanced</Component>
    }
  };
  // default enhancment, just decorate the display name of the parent component
  EnhanceComp.displayName = `Enhanced(${Component.displayName || Component.name})`;
  return EnhanceComp;
}


const MyWrappedComp = ({children}) => {
    return <div>My {children} Component</div>
};
const enhanced = enhance(MyWrappedComp);
// we want this to look like a normal <MyComp>
enhanced.displayName = 'MyComp';

@shilman
Copy link
Member Author

shilman commented Apr 22, 2017

Comment by gnarf
Friday Oct 21, 2016 at 17:34 GMT


I was digging into using the "real" source - but it's basically impossible unless you separate each story into it's own .js file and then just use webpacks raw-loader to load the source... I kind of hacked around and did something like this:

storiesOf('MyComponent')
  .addWithInfo('default', `
    ### Source:
\`\`\`js
${require('!!raw-loader!./MyComponent/default.js')}
\`\`\`
`, require('./MyComponent/default.js'))

Found out it works, but how much do we REALLY want that? :)

@shilman
Copy link
Member Author

shilman commented Apr 22, 2017

Comment by gnarf
Wednesday Oct 26, 2016 at 16:04 GMT


This is the more generalized code I was using in my storybook index.js: https://gist.github.com/gnarf/ea9bd0f76e36516b6f1f38e4aba542a3

I'm using this to export real "example code" for the story

@shilman
Copy link
Member Author

shilman commented Apr 22, 2017

Comment by mnmtanish
Thursday Oct 27, 2016 at 00:46 GMT


@madushan1000 is it possible to attach the source code with the component using the docgen plugin?
( bad idea! )

@shilman
Copy link
Member Author

shilman commented Apr 22, 2017

Comment by darioghilardi
Friday Dec 23, 2016 at 11:33 GMT


I just pushed #127 trying to provide a solution for this issue. If you want to provide some feedback it would be great.

@ndelangen
Copy link
Member

@mnmtanish I wonder why it's a bad idea?

@ndelangen
Copy link
Member

@darioghilardi can you explain your suggested solution here?

@aacotroneo
Copy link

can't we add an option like a displayName? it'd be an analogous design to the current propTables ... we can't tell by inspecting the code, so we tell explicitly what it is. Or support an extended syntax like propTables: [{myDisplayName: MyObject}, ...]

@thani-sh
Copy link
Contributor

Hi @ndelangen,
I was working on this feature and ran into something. I'm sorry I can't remember the reason. Please ignore that comment.

@stale
Copy link

stale bot commented Nov 27, 2017

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks!

@stale stale bot added the inactive label Nov 27, 2017
@stale
Copy link

stale bot commented Dec 12, 2017

Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

@stale stale bot closed this as completed Dec 12, 2017
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

6 participants