Skip to content

Commit

Permalink
Merge pull request #5819 from storybooks/5781-warn-mid-decorators
Browse files Browse the repository at this point in the history
ADD warning for decorators added "mid-kind"
  • Loading branch information
shilman committed Mar 3, 2019
1 parent 09c2987 commit ea173c1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 35 deletions.
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

0 comments on commit ea173c1

Please sign in to comment.