Export combineParameters and document in migrations

This commit is contained in:
Tom Coleman 2020-04-28 21:20:09 +10:00
parent 63682a297c
commit c0cdd3f004
3 changed files with 38 additions and 11 deletions

View File

@ -9,6 +9,7 @@
- [Rolling back](#rolling-back)
- [New addon presets](#new-addon-presets)
- [Removed Deprecated APIs](#removed-deprecated-apis)
- [New setStories event](#new-setstories-event)
- [Client API changes](#client-api-changes)
- [Removed Legacy Story APIs](#removed-legacy-story-apis)
- [Can no longer add decorators/parameters after stories](#can-no-longer-add-decoratorsparameters-after-stories)
@ -261,6 +262,31 @@ See the migration guides for further details:
- [Unified docs preset](#unified-docs-preset)
- [Addon centered decorator deprecated](#addon-centered-decorator-deprecated)
### New setStories event
The `setStories`/`SET_STORIES` event has changed and now denormalizes global and kind-level parameters. The new format of the event data is:
```js
{
globalParameters: { p: 'q' },
kindParameters: { kind: { p: 'q' } },
stories: /* as before but with only story-level parameters */
}
```
If you want the full denormalized parameters for a story, you can do something like:
```js
import { combineParameters } from '@storybook/api';
const story = data.stories[storyId];
const parameters = combineParameters(
data.globalParameters,
data.kindParameters[story.kind],
story.parameters
);
```
### Client API changes
#### Removed Legacy Story APIs

View File

@ -9,6 +9,7 @@ import React, {
useMemo,
useRef,
} from 'react';
import { mergeWith } from 'lodash';
import {
STORY_CHANGED,
@ -116,6 +117,15 @@ export interface Parameters {
[key: string]: any;
}
// This is duplicated from @storybook/client-api for the reasons mentioned in lib-addons/types.js
export const combineParameters = (...parameterSets: Parameters[]) =>
mergeWith({}, ...parameterSets, (objValue: any, srcValue: any) => {
// Treat arrays as scalars:
if (Array.isArray(srcValue)) return srcValue;
return undefined;
});
export type ModuleFn = (m: ModuleArgs) => Module;
interface Module {

View File

@ -1,9 +1,9 @@
import deprecate from 'util-deprecate';
import dedent from 'ts-dedent';
import { sanitize, parseKind } from '@storybook/csf';
import { mapValues, mergeWith } from 'lodash';
import { mapValues } from 'lodash';
import { StoryId, StoryKind, Args, Parameters } from '../index';
import { StoryId, StoryKind, Args, Parameters, combineParameters } from '../index';
import merge from './merge';
import { Provider } from '../modules/provider';
@ -140,15 +140,6 @@ const toGroup = (name: string) => ({
id: toKey(name),
});
// This is duplicated from @storybook/client-api for the reasons mentioned in lib-addons/types.js
const combineParameters = (...parameterSets: Parameters[]) =>
mergeWith({}, ...parameterSets, (objValue: any, srcValue: any) => {
// Treat arrays as scalars:
if (Array.isArray(srcValue)) return srcValue;
return undefined;
});
export const denormalizeStoryParameters = ({
globalParameters,
kindParameters,