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

ADD warning for decorators added "mid-kind" #5819

Merged
merged 3 commits into from
Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ storiesOf('Custom|Dependencies', module)
title: 'Component dependencies',
},
}))
.addDecorator(withKnobs)
.add('inputs and inject dependencies with knobs', () => ({
component: DiComponent,
props: {
title: text('title', 'Component dependencies'),
},
}));
.add(
'inputs and inject dependencies with knobs',
() => ({
component: DiComponent,
props: {
title: text('title', 'Component dependencies'),
},
}),
{
decorators: [withKnobs],
}
);
19 changes: 12 additions & 7 deletions examples/angular-cli/src/stories/custom-pipes.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ storiesOf('Custom|Pipes', module)
field: 'foobar',
},
}))
.addDecorator(withKnobs)
.add('With Knobs', () => ({
component: NameComponent,
props: {
field: text('field', 'foobar'),
},
}));
.add(
'With Knobs',
() => ({
component: NameComponent,
props: {
field: text('field', 'foobar'),
},
}),
{
decorators: [withKnobs],
}
);
25 changes: 15 additions & 10 deletions examples/angular-cli/src/stories/custom-providers.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ storiesOf('Custom|Providers', module)
name: 'Static name',
},
}))
.addDecorator(withKnobs)
.add('With knobs', () => {
const name = text('name', 'Dynamic knob');
.add(
'With knobs',
() => {
const name = text('name', 'Dynamic knob');

return {
component: ServiceComponent,
props: {
name,
},
};
});
return {
component: ServiceComponent,
props: {
name,
},
};
},
{
decorators: [withKnobs],
}
);
27 changes: 16 additions & 11 deletions examples/angular-cli/src/stories/custom-styles.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@ storiesOf('Custom|Style', module)
`,
],
}))
.addDecorator(withKnobs)
.add('With Knobs', () => ({
template: `<storybook-button-component [text]="text" (onClick)="onClick($event)"></storybook-button-component>`,
props: {
text: text('text', 'Button with custom styles'),
onClick: action('log'),
},
styles: [
`
.add(
'With Knobs',
() => ({
template: `<storybook-button-component [text]="text" (onClick)="onClick($event)"></storybook-button-component>`,
props: {
text: text('text', 'Button with custom styles'),
onClick: action('log'),
},
styles: [
`
storybook-button-component {
background-color: red;
padding: 25px;
}
`,
],
}));
],
}),
{
decorators: [withKnobs],
}
);
8 changes: 8 additions & 0 deletions lib/client-api/src/client_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export default class ClientApi {

const localDecorators = [];
let localParameters = {};
let hasAdded = false;
const api = {
kind,
};
Expand All @@ -148,6 +149,7 @@ export default class ClientApi {
});

api.add = (storyName, storyFn, parameters) => {
hasAdded = true;
const { _globalParameters, _globalDecorators } = this;
const id = toId(kind, storyName);

Expand Down Expand Up @@ -215,6 +217,12 @@ export default class ClientApi {
};

api.addDecorator = decorator => {
if (hasAdded) {
console.warn(`You have added a decorator to the kind '${kind}' after a story has already been added.
In Storybook 4 this applied the decorator only to subsequent stories. In Storybook 5+ it applies to all stories.
This is probably not what you intended. Read more here: https://github.com/storybooks/storybook/blob/master/MIGRATION.md`);
}

localDecorators.push(decorator);
return api;
};
Expand Down