From dc401dd810065e125f216a773fd8243602945748 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Sun, 3 Mar 2019 00:37:37 +1100 Subject: [PATCH 1/3] ADD a warning for #5781 --- lib/client-api/src/client_api.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/client-api/src/client_api.js b/lib/client-api/src/client_api.js index b9b7925fff8d..2c5991394e00 100644 --- a/lib/client-api/src/client_api.js +++ b/lib/client-api/src/client_api.js @@ -134,6 +134,7 @@ export default class ClientApi { const localDecorators = []; let localParameters = {}; + let hasAdded = false; const api = { kind, }; @@ -148,6 +149,7 @@ export default class ClientApi { }); api.add = (storyName, storyFn, parameters) => { + hasAdded = true; const { _globalParameters, _globalDecorators } = this; const id = toId(kind, storyName); @@ -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; }; From 4753e202d3eb1f9449c4d9a74304a07eb0b2d314 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Sun, 3 Mar 2019 11:04:35 +1100 Subject: [PATCH 2/3] ADD new story-level decorators to angular di stories --- .../component-with-di/di.component.stories.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/angular-cli/src/stories/component-with-di/di.component.stories.ts b/examples/angular-cli/src/stories/component-with-di/di.component.stories.ts index 6059f9ecc779..a553eb7ac001 100644 --- a/examples/angular-cli/src/stories/component-with-di/di.component.stories.ts +++ b/examples/angular-cli/src/stories/component-with-di/di.component.stories.ts @@ -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], + } + ); From 79609ae984595241c4fef8b60a4fa76f5ee880eb Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Sun, 3 Mar 2019 12:55:47 +0800 Subject: [PATCH 3/3] ADD new story-level decorators to angular stories --- .../src/stories/custom-pipes.stories.ts | 19 ++++++++----- .../src/stories/custom-providers.stories.ts | 25 ++++++++++------- .../src/stories/custom-styles.stories.ts | 27 +++++++++++-------- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/examples/angular-cli/src/stories/custom-pipes.stories.ts b/examples/angular-cli/src/stories/custom-pipes.stories.ts index b342d530c21c..9bb29bc75ba7 100644 --- a/examples/angular-cli/src/stories/custom-pipes.stories.ts +++ b/examples/angular-cli/src/stories/custom-pipes.stories.ts @@ -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], + } + ); diff --git a/examples/angular-cli/src/stories/custom-providers.stories.ts b/examples/angular-cli/src/stories/custom-providers.stories.ts index d7ca9ed069be..12814781bcd0 100644 --- a/examples/angular-cli/src/stories/custom-providers.stories.ts +++ b/examples/angular-cli/src/stories/custom-providers.stories.ts @@ -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], + } + ); diff --git a/examples/angular-cli/src/stories/custom-styles.stories.ts b/examples/angular-cli/src/stories/custom-styles.stories.ts index df2e1b20a78c..fc14f680dde0 100644 --- a/examples/angular-cli/src/stories/custom-styles.stories.ts +++ b/examples/angular-cli/src/stories/custom-styles.stories.ts @@ -24,19 +24,24 @@ storiesOf('Custom|Style', module) `, ], })) - .addDecorator(withKnobs) - .add('With Knobs', () => ({ - template: ``, - props: { - text: text('text', 'Button with custom styles'), - onClick: action('log'), - }, - styles: [ - ` + .add( + 'With Knobs', + () => ({ + template: ``, + props: { + text: text('text', 'Button with custom styles'), + onClick: action('log'), + }, + styles: [ + ` storybook-button-component { background-color: red; padding: 25px; } `, - ], - })); + ], + }), + { + decorators: [withKnobs], + } + );