Browse Source

Increased Prettier line-width for examples

main
Brian Vaughn 7 years ago
parent
commit
36963886eb
  1. 9
      examples/16-3-release-blog-create-ref.js
  2. 10
      examples/update-on-async-rendering/adding-event-listeners-after.js
  3. 5
      examples/update-on-async-rendering/adding-event-listeners-before.js
  4. 6
      examples/update-on-async-rendering/fetching-external-data-after.js
  5. 6
      examples/update-on-async-rendering/fetching-external-data-before.js
  6. 5
      examples/update-on-async-rendering/initializing-state-after.js
  7. 5
      examples/update-on-async-rendering/initializing-state-before.js
  8. 12
      examples/update-on-async-rendering/invoking-external-callbacks-after.js
  9. 12
      examples/update-on-async-rendering/invoking-external-callbacks-before.js
  10. 4
      examples/update-on-async-rendering/side-effects-in-constructor.js
  11. 16
      examples/update-on-async-rendering/updating-state-from-props-after.js
  12. 10
      examples/update-on-async-rendering/updating-state-from-props-before.js
  13. 5
      examples/update-on-async-rendering/using-react-lifecycles-compat.js

9
examples/16-3-release-blog-create-ref.js

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

10
examples/update-on-async-rendering/adding-event-listeners-after.js

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

5
examples/update-on-async-rendering/adding-event-listeners-before.js

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

6
examples/update-on-async-rendering/fetching-external-data-after.js

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

6
examples/update-on-async-rendering/fetching-external-data-before.js

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

5
examples/update-on-async-rendering/initializing-state-after.js

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

5
examples/update-on-async-rendering/initializing-state-before.js

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

12
examples/update-on-async-rendering/invoking-external-callbacks-after.js

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

12
examples/update-on-async-rendering/invoking-external-callbacks-before.js

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

4
examples/update-on-async-rendering/side-effects-in-constructor.js

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

16
examples/update-on-async-rendering/updating-state-from-props-after.js

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

10
examples/update-on-async-rendering/updating-state-from-props-before.js

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

5
examples/update-on-async-rendering/using-react-lifecycles-compat.js

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

Loading…
Cancel
Save