Skip to content

Commit

Permalink
Stop using deprecated React methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypnosphi committed Mar 30, 2018
1 parent 9bbe5cc commit cdb7cab
Show file tree
Hide file tree
Showing 36 changed files with 195 additions and 131 deletions.
28 changes: 15 additions & 13 deletions addons/background/src/BackgroundPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class BackgroundPanel extends Component {
constructor(props) {
super(props);

const { channel, api } = props;
const { channel } = props;

// A channel is explicitly passed in for testing
if (channel) {
Expand All @@ -73,6 +73,20 @@ export default class BackgroundPanel extends Component {
}

this.state = { backgrounds: [] };
}

componentDidMount() {
this.iframe = document.getElementById(storybookIframe);

if (!this.iframe) {
throw new Error('Cannot find Storybook iframe');
}

Object.keys(style.iframe).forEach(prop => {
this.iframe.style[prop] = style.iframe[prop];
});

const { api } = this.props;

this.channel.on('background-set', backgrounds => {
this.setState({ backgrounds });
Expand All @@ -93,18 +107,6 @@ export default class BackgroundPanel extends Component {
});
}

componentDidMount() {
this.iframe = document.getElementById(storybookIframe);

if (!this.iframe) {
throw new Error('Cannot find Storybook iframe');
}

Object.keys(style.iframe).forEach(prop => {
this.iframe.style[prop] = style.iframe[prop];
});
}

setBackgroundFromSwatch = background => {
this.updateIframe(background);
this.props.api.setQueryParams({ background });
Expand Down
14 changes: 3 additions & 11 deletions addons/background/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,26 @@ export class BackgroundDecorator extends React.Component {
constructor(props) {
super(props);

const { channel, story } = props;
const { channel } = props;

// A channel is explicitly passed in for testing
if (channel) {
this.channel = channel;
} else {
this.channel = addons.getChannel();
}

this.story = story();
}

componentWillMount() {
componentDidMount() {
this.channel.emit('background-set', this.props.backgrounds);
}

componentWillReceiveProps(nextProps) {
if (nextProps.story !== this.props.story) {
this.story = nextProps.story();
}
}

componentWillUnmount() {
this.channel.emit('background-unset');
}

render() {
return this.story;
return this.props.story();
}
}
BackgroundDecorator.propTypes = {
Expand Down
2 changes: 1 addition & 1 deletion addons/centered/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"global": "^4.3.2"
},
"devDependencies": {
"react-dom": "^16.2.0"
"react-dom": "^16.3.0"
},
"peerDependencies": {
"react": "*"
Expand Down
2 changes: 1 addition & 1 deletion addons/info/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"devDependencies": {
"@storybook/addon-actions": "4.0.0-alpha.1",
"@storybook/react": "4.0.0-alpha.1",
"react-test-renderer": "^16.1.0"
"react-test-renderer": "^16.3.0"
},
"peerDependencies": {
"react": "*",
Expand Down
3 changes: 3 additions & 0 deletions addons/knobs/src/components/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export default class Panel extends React.Component {

this.lastEdit = getTimestamp();
this.loadedFromUrl = false;
}

componentDidMount() {
this.props.channel.on('addon:knobs:setKnobs', this.setKnobs);
this.props.channel.on('addon:knobs:setOptions', this.setOptions);

Expand Down
4 changes: 2 additions & 2 deletions addons/links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"devDependencies": {
"@storybook/react": "4.0.0-alpha.1",
"enzyme": "^3.3.0",
"react": "^16.1.0",
"react-dom": "^16.1.0"
"react": "^16.3.0",
"react-dom": "^16.3.0"
},
"peerDependencies": {
"@storybook/addons": "^3.3.0",
Expand Down
4 changes: 2 additions & 2 deletions addons/storyshots/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"@storybook/addons": "4.0.0-alpha.1",
"@storybook/react": "4.0.0-alpha.1",
"enzyme-to-json": "^3.3.3",
"react": "^16.1.0",
"react-dom": "^16.1.0"
"react": "^16.3.0",
"react-dom": "^16.3.0"
},
"peerDependencies": {
"@storybook/addons": "4.0.0-alpha.1",
Expand Down
12 changes: 7 additions & 5 deletions addons/storysource/src/StoryPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ export default class StoryPanel extends Component {

this.state = { source: '// Here will be dragons 🐉' };

const { channel } = props;
this.setSelectedStoryRef = this.setSelectedStoryRef.bind(this);
this.lineRenderer = this.lineRenderer.bind(this);
this.clickOnStory = this.clickOnStory.bind(this);
}

componentDidMount() {
const { channel } = this.props;

channel.on(EVENT_ID, ({ source, currentLocation, locationsMap }) => {
const locationsKeys = StoryPanel.getLocationKeys(locationsMap);
Expand All @@ -58,10 +64,6 @@ export default class StoryPanel extends Component {
locationsKeys,
});
});

this.setSelectedStoryRef = this.setSelectedStoryRef.bind(this);
this.lineRenderer = this.lineRenderer.bind(this);
this.clickOnStory = this.clickOnStory.bind(this);
}

componentDidUpdate() {
Expand Down
4 changes: 2 additions & 2 deletions app/mithril/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
"html-webpack-plugin": "^3.1.0",
"json5": "^0.5.1",
"markdown-loader": "^2.0.2",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react": "^16.3.0",
"react-dom": "^16.3.0",
"util-deprecate": "^1.0.2",
"webpack": "^4.4.1",
"webpack-hot-middleware": "^2.21.2"
Expand Down
4 changes: 2 additions & 2 deletions app/polymer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
"global": "^4.3.2",
"html-webpack-plugin": "^3.1.0",
"json5": "^0.5.1",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react": "^16.3.0",
"react-dom": "^16.3.0",
"util-deprecate": "^1.0.2",
"webpack": "^4.4.1",
"webpack-hot-middleware": "^2.21.2"
Expand Down
1 change: 1 addition & 0 deletions app/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"babel-runtime": "^6.26.0",
"case-sensitive-paths-webpack-plugin": "^2.1.2",
"commander": "^2.15.1",
"dotenv-webpack": "^1.5.5",
"express": "^4.16.3",
"find-cache-dir": "^1.0.0",
"global": "^4.3.2",
Expand Down
2 changes: 2 additions & 0 deletions app/react-native/src/server/config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import webpack from 'webpack';
import Dotenv from 'dotenv-webpack';
import WatchMissingNodeModulesPlugin from '@storybook/react-dev-utils/WatchMissingNodeModulesPlugin';
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
Expand Down Expand Up @@ -27,6 +28,7 @@ const getConfig = options => ({
new webpack.HotModuleReplacementPlugin(),
new CaseSensitivePathsPlugin(),
new WatchMissingNodeModulesPlugin(nodeModulesPaths),
new Dotenv({ silent: true }),
],
module: {
rules: [
Expand Down
2 changes: 2 additions & 0 deletions app/react-native/src/server/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import webpack from 'webpack';
import Dotenv from 'dotenv-webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import { includePaths, excludePaths } from './utils';

Expand Down Expand Up @@ -31,6 +32,7 @@ const getConfig = options => {
}),
new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }),
new webpack.optimize.DedupePlugin(),
new Dotenv({ silent: true }),
],
module: {
rules: [
Expand Down
4 changes: 2 additions & 2 deletions app/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"peerDependencies": {
"babel-core": "^6.26.0 || ^7.0.0-0",
"babel-runtime": ">=6.0.0",
"react": ">=15.0.0 || ^16.0.0",
"react-dom": ">=15.0.0 || ^16.0.0"
"react": ">=15.0.0",
"react-dom": ">=15.0.0"
}
}
15 changes: 11 additions & 4 deletions app/react/src/client/preview/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ if (isBrowser) {
rootEl = document.getElementById('root');
}

function render(node, el) {
ReactDOM.render(
process.env.STORYBOOK_EXAMPLE_APP ? <React.StrictMode>{node}</React.StrictMode> : node,
el
);
}

export function renderError(error) {
const properError = new Error(error.title);
properError.stack = error.description;

const redBox = <ErrorDisplay error={properError} />;
ReactDOM.render(redBox, rootEl);
render(redBox, rootEl);
}

export function renderException(error) {
Expand All @@ -33,7 +40,7 @@ export function renderException(error) {
const realError = new Error(error.message);
realError.stack = error.stack;
const redBox = <ErrorDisplay error={realError} />;
ReactDOM.render(redBox, rootEl);
render(redBox, rootEl);

// Log the stack to the console. So, user could check the source code.
logger.error(error.stack);
Expand All @@ -49,7 +56,7 @@ export function renderMain(data, storyStore, forceRender) {
const revision = storyStore.getRevision();
const story = storyStore.getStoryWithContext(selectedKind, selectedStory);
if (!story) {
ReactDOM.render(noPreview, rootEl);
render(noPreview, rootEl);
return null;
}

Expand Down Expand Up @@ -101,7 +108,7 @@ export function renderMain(data, storyStore, forceRender) {
return renderError(error);
}

ReactDOM.render(element, rootEl);
render(element, rootEl);
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions app/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"html-webpack-plugin": "^3.1.0",
"json5": "^0.5.1",
"markdown-loader": "^2.0.2",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react": "^16.3.0",
"react-dom": "^16.3.0",
"util-deprecate": "^1.0.2",
"webpack": "^4.4.1",
"webpack-hot-middleware": "^2.21.2"
Expand Down
1 change: 1 addition & 0 deletions examples/angular-cli/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
STORYBOOK_EXAMPLE_APP=true
4 changes: 2 additions & 2 deletions examples/cra-kitchen-sink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"dependencies": {
"global": "^4.3.2",
"prop-types": "^15.6.1",
"react": "^16.2.0",
"react-dom": "^16.2.0"
"react": "^16.3.0",
"react-dom": "^16.3.0"
},
"devDependencies": {
"@storybook/addon-a11y": "4.0.0-alpha.1",
Expand Down
1 change: 1 addition & 0 deletions examples/crna-kitchen-sink/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
STORYBOOK_EXAMPLE_APP=true
1 change: 1 addition & 0 deletions examples/mithril-kitchen-sink/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
STORYBOOK_EXAMPLE_APP=true
1 change: 0 additions & 1 deletion examples/mithril-kitchen-sink/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ build

# misc
.DS_Store
.env
npm-debug.log
1 change: 1 addition & 0 deletions examples/official-storybook/.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
DISPLAY_WARNING=none
STORYBOOK_EXAMPLE_APP=true
4 changes: 2 additions & 2 deletions examples/official-storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"global": "^4.3.2",
"paths.macro": "^2.0.2",
"prop-types": "^15.6.1",
"react": "^16.2.0",
"react": "^16.3.0",
"react-chromatic": "^0.8.1",
"react-dom": "^16.2.0",
"react-dom": "^16.3.0",
"uuid": "^3.2.1"
}
}
1 change: 1 addition & 0 deletions examples/polymer-cli/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
STORYBOOK_EXAMPLE_APP=true
1 change: 1 addition & 0 deletions examples/react-native-vanilla/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
STORYBOOK_EXAMPLE_APP=true
16 changes: 8 additions & 8 deletions lib/components/src/navigation/routed_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ const LEFT_BUTTON = 0;
const isPlainLeftClick = e =>
e.button === LEFT_BUTTON && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey;

const wrapOnClick = fn => e => (isPlainLeftClick(e) ? e.preventDefault() || fn(e) : false);

export default class RoutedLink extends React.Component {
constructor(props, ...rest) {
super(...[props, ...rest]);
constructor(...attrs) {
super(...attrs);

const { onClick } = props;
this.onClick = onClick ? wrapOnClick(onClick) : undefined;
this.onClick = this.onClick.bind(this);
}

componentWillUpdate({ onClick }) {
this.onClick = wrapOnClick(onClick);
onClick(e) {
if (isPlainLeftClick(e)) {
e.preventDefault();
this.props.onClick(e);
}
}

render() {
Expand Down
6 changes: 4 additions & 2 deletions lib/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
"postcss-loader": "^2.1.3",
"prop-types": "^15.6.1",
"qs": "^6.5.1",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"redux": "^3.7.2",
"serve-favicon": "^2.4.5",
"shelljs": "^0.8.1",
Expand All @@ -48,5 +46,9 @@
"webpack": "^4.4.1",
"webpack-dev-middleware": "^3.1.0",
"webpack-hot-middleware": "^2.21.2"
},
"peerDependencies": {
"react": ">=15.0.0",
"react-dom": ">=15.0.0"
}
}
3 changes: 2 additions & 1 deletion lib/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@storybook/components": "4.0.0-alpha.1",
"@storybook/mantra-core": "^1.7.2",
"@storybook/podda": "^1.2.3",
"@storybook/react-komposer": "^2.0.3",
"@storybook/react-komposer": "^2.0.4",
"babel-runtime": "^6.26.0",
"deep-equal": "^1.0.1",
"events": "^2.0.0",
Expand All @@ -33,6 +33,7 @@
"qs": "^6.5.1",
"react-fuzzy": "^0.5.2",
"react-icons": "^2.2.7",
"react-lifecycles-compat": "^1.1.0",
"react-modal": "^3.3.2",
"react-split-pane": "^0.1.77",
"react-treebeard": "^2.1.0"
Expand Down
Loading

0 comments on commit cdb7cab

Please sign in to comment.