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

Warn if story with a given name already exists #670

Merged

Conversation

evgenykochetkov
Copy link
Contributor

Right now if you add another story with the same name, the first one is
lost. For example:

// …

storiesOf('Button', module)
  .add('with text', () => ( // this story will be lost
    <Button onClick={action('clicked')}>Hello Button</Button>
  ))
  .add('with some emoji', () => (
    <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>
  ))
  .add('with text', () => (
    <p>
      this will silently overwrite the first story
    </p>
  ));

Right now if you add another story with the same name, the first one is
lost. For example:

```js
// …

storiesOf('Button', module)
  .add('with text', () => ( // this story will be lost
    <Button onClick={action('clicked')}>Hello Button</Button>
  ))
  .add('with some emoji', () => (
    <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>
  ))
  .add('with text', () => (
    <p>
      this will silently overwrite the first story
    </p>
  ));
```
@@ -11,6 +11,10 @@ export default class StoryStore {
}

addStory(kind, name, fn) {
if (this.hasStory(kind, name)) {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@@ -45,6 +45,10 @@ export default class ClientApi {
});

api.add = (storyName, getStory) => {
if (this._storyStore.hasStory(kind, storyName)) {
throw new Error(`Story of "${kind}" named "${storyName}" alredy exists`);
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: alredy/already

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Fixed it.

"alredy" -> "already"
@ndelangen ndelangen merged commit a930b0c into storybookjs:master Mar 28, 2017
@ndelangen
Copy link
Member

Thank you so much!

@usulpro
Copy link
Member

usulpro commented Mar 29, 2017

Doesn't it break any existing projects or addons which works with stories dynamically?

@ndelangen
Copy link
Member

Do you have examples of this? If this is indeed a common thing addons do, We need to think of something else.

@ndelangen
Copy link
Member

@usulpro Do you think this is a real issue?

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

Successfully merging this pull request may close these issues.

6 participants