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

Fix propTypes in addon-background #2279

Merged
merged 3 commits into from
Nov 9, 2017
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
7 changes: 5 additions & 2 deletions addons/background/src/BackgroundPanel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import addons from '@storybook/addons';
import EventEmitter from 'events';

import Swatch from './Swatch';

Expand Down Expand Up @@ -118,7 +117,11 @@ BackgroundPanel.propTypes = {
getQueryParam: PropTypes.func,
setQueryParams: PropTypes.func,
}).isRequired,
channel: PropTypes.instanceOf(EventEmitter),
channel: PropTypes.shape({
emit: PropTypes.func,
Copy link
Member

@danielduan danielduan Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't all of these be required if the channel is supplied? should the channel be required as well?

Copy link
Member Author

@Hypnosphi Hypnosphi Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a defaultProp for channel, so it shouldn't be marked as required. As for particular shape, I basically just copypasted it from addons/knobs (and it's the same as in addons/events)

Copy link
Member Author

@Hypnosphi Hypnosphi Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should have this propTypes shape exported in @storybook/addons and use it elsewhere. There is a couple of places with this line, which can be replaced with the shape as well:

channel: PropTypes.object, // eslint-disable-line react/forbid-prop-types

You can open a PR with such a refactoring if you feel like it =)

on: PropTypes.func,
removeListener: PropTypes.func,
}),
};
BackgroundPanel.defaultProps = {
channel: undefined,
Expand Down
7 changes: 5 additions & 2 deletions addons/background/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import EventEmitter from 'events';

import addons from '@storybook/addons';

Expand Down Expand Up @@ -63,7 +62,11 @@ export class BackgroundDecorator extends React.Component {
}
BackgroundDecorator.propTypes = {
backgrounds: PropTypes.arrayOf(PropTypes.object),
channel: PropTypes.instanceOf(EventEmitter),
channel: PropTypes.shape({
emit: PropTypes.func,
on: PropTypes.func,
removeListener: PropTypes.func,
}),
story: PropTypes.func.isRequired,
};
BackgroundDecorator.defaultProps = {
Expand Down