Increased Prettier line-width for examples

This commit is contained in:
Brian Vaughn
2018-02-07 08:20:34 -08:00
parent 06d5be4571
commit 36963886eb
13 changed files with 31 additions and 74 deletions

View File

@@ -3,13 +3,8 @@ class MyComponent extends React.Component {
divRef = React.createRef();
render() {
// highlight-range{4}
return (
<input
type="text"
ref={this.divRef}
/>
);
// highlight-next-line
return <input type="text" ref={this.divRef} />;
}
componentDidMount() {

View File

@@ -1,12 +1,11 @@
// After
class ExampleComponent extends React.Component {
// highlight-range{1-4}
// highlight-range{1-3}
state = {
subscribedValue: this.props
.dataSource.value,
subscribedValue: this.props.dataSource.value,
};
// highlight-range{1-19}
// highlight-range{1-18}
componentDidMount() {
// Event listeners are only safe to add after mount,
// So they won't leak if mount is interrupted or errors.
@@ -21,8 +20,7 @@ class ExampleComponent extends React.Component {
this.props.dataSource.value
) {
this.setState({
subscribedValue: this.props
.dataSource.value,
subscribedValue: this.props.dataSource.value,
});
}
}

View File

@@ -1,10 +1,9 @@
// Before
class ExampleComponent extends React.Component {
// highlight-range{1-11}
// highlight-range{1-10}
componentWillMount() {
this.setState({
subscribedValue: this.props
.dataSource.value,
subscribedValue: this.props.dataSource.value,
});
// This is not safe; it can leak!

View File

@@ -7,11 +7,9 @@ class ExampleComponent extends React.Component {
externalData: null,
};
// highlight-range{1-9}
// highlight-range{1-7}
componentDidMount() {
asyncLoadData(
this.props.someId
).then(externalData => {
asyncLoadData(this.props.someId).then(externalData => {
if (!this._hasUnmounted) {
this.setState({externalData});
}

View File

@@ -4,11 +4,9 @@ class ExampleComponent extends React.Component {
externalData: null,
};
// highlight-range{1-7}
// highlight-range{1-5}
componentWillMount() {
asyncLoadData(
this.props.someId
).then(externalData =>
asyncLoadData(this.props.someId).then(externalData =>
this.setState({externalData})
);
}

View File

@@ -1,9 +1,8 @@
// After
class ExampleComponent extends React.Component {
// highlight-range{1-5}
// highlight-range{1-4}
state = {
currentColor: this.props
.defaultColor,
currentColor: this.props.defaultColor,
palette: 'rgb',
};
}

View File

@@ -2,11 +2,10 @@
class ExampleComponent extends React.Component {
state = {};
// highlight-range{1-7}
// highlight-range{1-6}
componentWillMount() {
this.setState({
currentColor: this.props
.defaultColor,
currentColor: this.props.defaultColor,
palette: 'rgb',
});
}

View File

@@ -1,18 +1,12 @@
// After
class ExampleComponent extends React.Component {
// highlight-next-line
componentDidUpdate(
prevProps,
prevState
) {
// highlight-range{1-8}
// highlight-range{1-8}
componentDidUpdate(prevProps, prevState) {
if (
this.state.someStatefulValue !==
prevState.someStatefulValue
) {
this.props.onChange(
this.state.someStatefulValue
);
this.props.onChange(this.state.someStatefulValue);
}
}
}

View File

@@ -1,18 +1,12 @@
// Before
class ExampleComponent extends React.Component {
// highlight-next-line
componentWillUpdate(
nextProps,
nextState
) {
// highlight-range{1-8}
// highlight-range{1-8}
componentWillUpdate(nextProps, nextState) {
if (
this.state.someStatefulValue !==
nextState.someStatefulValue
) {
nextProps.onChange(
nextState.someStatefulValue
);
nextProps.onChange(nextState.someStatefulValue);
}
}
}

View File

@@ -2,8 +2,6 @@ class TopLevelRoute extends React.Component {
constructor(props) {
super(props);
SharedApplicationState.recordEvent(
'ExampleComponent'
);
SharedApplicationState.recordEvent('ExampleComponent');
}
}

View File

@@ -5,21 +5,13 @@ class ExampleComponent extends React.Component {
// highlight-next-line
state = {};
// highlight-next-line
static getDerivedStateFromProps(
nextProps,
prevState
) {
// highlight-range{1-11}
if (
nextProps.currentRow !==
prevState.lastRow
) {
// highlight-range{1-8}
static getDerivedStateFromProps(nextProps, prevState) {
if (nextProps.currentRow !== prevState.lastRow) {
return {
lastRow: nextProps.currentRow,
isScrollingDown:
nextProps.currentRow >
prevState.lastRow,
nextProps.currentRow > prevState.lastRow,
};
}

View File

@@ -4,16 +4,12 @@ class ExampleComponent extends React.Component {
isScrollingDown: false,
};
// highlight-range{1-12}
// highlight-range{1-8}
componentWillReceiveProps(nextProps) {
if (
this.props.currentRow !==
nextProps.currentRow
) {
if (this.props.currentRow !== nextProps.currentRow) {
this.setState({
isScrollingDown:
nextProps.currentRow >
this.props.currentRow,
nextProps.currentRow > this.props.currentRow,
});
}
}

View File

@@ -4,10 +4,7 @@ import polyfill from 'react-lifecycles-compat';
class ExampleComponent extends React.Component {
// highlight-next-line
static getDerivedStateFromProps(
nextProps,
prevState
) {
static getDerivedStateFromProps(nextProps, prevState) {
// Your state update logic here ...
}
}