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

REMOVE previously deprecated default export from backgrounds #5828

Merged
merged 6 commits into from
Mar 4, 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
31 changes: 27 additions & 4 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- [Story hierarchy defaults](#story-hierarchy-defaults)
- [Options addon deprecated](#options-addon-deprecated)
- [Individual story decorators](#individual-story-decorators)
- [Addon backgrounds uses parameters](#addon-backgrounds-uses-parameters)
- [Addon viewport uses parameters](#addon-backgrounds-uses-parameters)
- [From version 4.0.x to 4.1.x](#from-version-40x-to-41x)
- [Private addon config](#private-addon-config)
- [React 15.x](#react-15x)
Expand Down Expand Up @@ -163,6 +165,25 @@ storiesOf('Stories', module)
.add('centered', () => 'Hello', { decorators: [centered] });
```

## Addon backgrounds uses parameters

Similarly, `@storybook/addon-backgrounds` uses parameters to pass background options. If you previously had:

```js
import { withBackgrounds } from `@storybook/addon-backgrounds`;

storiesOf('Stories', module)
.addDecorator(withBackgrounds(options));
```

You should replace it with:

```js
storiesOf('Stories', module).addParameters({ backgrounds: options });
```

You can pass `backgrounds` parameters at the global level (via `addParameters` imported from `@storybook/react` et al.), and the story level (via the third argument to `.add()`).

## Addon viewport uses parameters

Similarly, `@storybook/addon-viewport` uses parameters to pass viewport options. If you previously had:
Expand All @@ -173,7 +194,7 @@ import { configureViewport } from `@storybook/addon-viewport`;
configureViewport(options);
```

You can replace it with:
You should replace it with:

```js
import { addParameters } from '@storybook/react'; // or others
Expand Down Expand Up @@ -214,17 +235,19 @@ However, if you're developing React components, this means you need to upgrade t
Also, here's the error you'll get if you're running an older version of React:

```

core.browser.esm.js:15 Uncaught TypeError: Object(...) is not a function
at Module../node_modules/@emotion/core/dist/core.browser.esm.js (core.browser.esm.js:15)
at **webpack_require** (bootstrap:724)
at __webpack_require__ (bootstrap:724)
at fn (bootstrap:101)
at Module../node_modules/@emotion/styled-base/dist/styled-base.browser.esm.js (styled-base.browser.esm.js:1)
at **webpack_require** (bootstrap:724)
at __webpack_require__ (bootstrap:724)
at fn (bootstrap:101)
at Module../node_modules/@emotion/styled/dist/styled.esm.js (styled.esm.js:1)
at **webpack_require** (bootstrap:724)
at __webpack_require__ (bootstrap:724)
at fn (bootstrap:101)
at Object../node_modules/@storybook/components/dist/navigation/MenuLink.js (MenuLink.js:12)

```

### Generic addons
Expand Down
1 change: 0 additions & 1 deletion addons/backgrounds/mithril.js

This file was deleted.

5 changes: 0 additions & 5 deletions addons/backgrounds/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
export const ADDON_ID = 'storybook/background';
export const PARAM_KEY = 'backgrounds';

export const EVENTS = {
SET: `${ADDON_ID}:set`,
UNSET: `${ADDON_ID}:unset`,
};
8 changes: 0 additions & 8 deletions addons/backgrounds/src/deprecated.ts

This file was deleted.

49 changes: 12 additions & 37 deletions addons/backgrounds/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,18 @@
import { addons, makeDecorator, StoryContext, StoryGetter, WrapperSettings } from '@storybook/addons';
import { makeDecorator, StoryContext, StoryGetter } from '@storybook/addons';
import deprecate from 'util-deprecate';

import { REGISTER_SUBSCRIPTION } from '@storybook/core-events';
import { EVENTS } from './constants';
import { BackgroundConfig } from './models';

let prevBackgrounds: BackgroundConfig[];

const subscription = () => () => {
prevBackgrounds = null;
addons.getChannel().emit(EVENTS.UNSET);
};

export const withBackgrounds = makeDecorator({
name: 'withBackgrounds',
parameterName: 'backgrounds',
skipIfNoParametersOrOptions: true,
allowDeprecatedUsage: true,
wrapper: (getStory: StoryGetter, context: StoryContext, { options, parameters }: WrapperSettings) => {
const data = parameters || options || [];
const backgrounds = Array.isArray(data) ? data : Object.values(data);

if (backgrounds.length === 0) {
// This decorator is kept purely so we produce a decorator that is compatible with both
// `addDecorator(withBackgrounds(...))` and `addDecorator(withBackgrounds)`
export const withBackgrounds = deprecate(
makeDecorator({
name: 'withBackgrounds',
parameterName: 'backgrounds',
wrapper: (getStory: StoryGetter, context: StoryContext) => {
return getStory(context);
}

if (prevBackgrounds !== backgrounds) {
addons.getChannel().emit(EVENTS.SET, backgrounds);
prevBackgrounds = backgrounds;
}
addons.getChannel().emit(REGISTER_SUBSCRIPTION, subscription);

return getStory(context);
},
});

export default deprecate(
withBackgrounds,
'The default export of @storybook/addon-backgrounds is deprecated, please `import { withBackgrounds }` instead'
},
}),
`Note that withBackgrounds(options) has been replaced by addParameters({ backgrounds: options})
Read more about it in the migration guide: https://github.com/storybooks/storybook/blob/master/MIGRATION.md`
);

if (module && module.hot && module.hot.decline) {
Expand Down
1 change: 0 additions & 1 deletion addons/backgrounds/vue.js

This file was deleted.