From 1f921612adc15a647705fcfabdaf9c72e6b8743e Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Fri, 19 Jul 2019 21:11:35 +0800 Subject: [PATCH] Module format load: Move story decorators out of parameters --- .../stories/addon-info/options.stories.js | 4 +--- .../stories/core/decorators.stories.js | 14 +++++++++++++- lib/core/src/client/preview/start.js | 9 +++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/examples/official-storybook/stories/addon-info/options.stories.js b/examples/official-storybook/stories/addon-info/options.stories.js index 95d04d672da..d87384bcc59 100644 --- a/examples/official-storybook/stories/addon-info/options.stories.js +++ b/examples/official-storybook/stories/addon-info/options.stories.js @@ -140,9 +140,7 @@ export const useInfoAsStoryDecorator = () => ; useInfoAsStoryDecorator.story = { name: 'Use Info as story decorator', - parameters: { - decorators: [withInfo('Info can take options via the global or local decorator as well.')], - }, + decorators: [withInfo('Info can take options via the global or local decorator as well.')], }; export const usingParamatersAcrossAllStories = () => ; diff --git a/examples/official-storybook/stories/core/decorators.stories.js b/examples/official-storybook/stories/core/decorators.stories.js index 314ac930838..6d301a93db5 100644 --- a/examples/official-storybook/stories/core/decorators.stories.js +++ b/examples/official-storybook/stories/core/decorators.stories.js @@ -28,11 +28,23 @@ export default { export const all = () =>

Story

; all.story = { + decorators: [ + s => ( + <> +

Local Decorator

+ {s()} + + ), + ], +}; + +export const deprecated = () =>

Story

; +deprecated.story = { parameters: { decorators: [ s => ( <> -

Local Decorator

+

Deprecated Local Decorator

{s()} ), diff --git a/lib/core/src/client/preview/start.js b/lib/core/src/client/preview/start.js index 35fff24b5fe..39044742fae 100644 --- a/lib/core/src/client/preview/start.js +++ b/lib/core/src/client/preview/start.js @@ -349,8 +349,13 @@ export default function start(render, { decorateStory } = {}) { Object.keys(exports).forEach(key => { if (isExportStory(key, meta)) { const storyFn = exports[key]; - const { name, parameters } = storyFn.story || {}; - kind.add(name || key, storyFn, parameters); + const { name, parameters, decorators } = storyFn.story || {}; + if (parameters && parameters.decorators) { + deprecate(() => {}, + `${kindName} => ${name || key}: story.parameters.decorators is deprecated; use story.decorators instead.`)(); + } + const decoratorParams = decorators ? { decorators } : null; + kind.add(name || key, storyFn, { ...parameters, ...decoratorParams }); } });