Skip to content

Commit 2beec2f

Browse files
authored
createClass + PropTypes + checkPropTypes warnings (facebook#9399)
(Temporarily) re-adds getters with deprecation warnings for React.PropTypes, React.checkPropTypes, and React.createClass. * 08bd020: Replace all references to React.PropTypes with prop-types to avoid triggering our own warning message. * ef5b5c6: Removed several references to React.createClass that appeared after rebasing this branch. (reviewed by @flarnie) * 524ce20: Added getters for createClass and PropTypes to the main React isomorphic object, behind one-time warning messages. (reviewed by @spicyj) * db48f54: Fixed Rollup bundles to inline 'prop-types' and 'create-react-class' for UMD builds only. (reviewed by @spicyj, @trueadm ) * cf49cfd: Updated tests-passing.txt to remove tests that were deleted in this branch. * d34109a: Responses to PR feedback from @spicyj. (Added package.json dependencies to packages/react and packages/react-dom. Renamed a var. Expanded on an inline comment.) * 488c8d2: Added warning for moved package to React.checkPropTypes accessor too and updated build script. * 83bcb29: Wordsmithing for deprecation notices (added fb.me links). * afdc9d2: Tweaked legacy module inlining to remove order-of-deps constraint * d1348b9: Removed $FlowFixMe. * 7dbc3e7: More wordsmithing of deprecation notices based on Dan's feedback.
1 parent aa1f868 commit 2beec2f

File tree

59 files changed

+734
-1397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+734
-1397
lines changed

fixtures/art/VectorWidget.js

+17-19
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ var BASE_VEL = 0.15;
2424
/**
2525
* An animated SVG component.
2626
*/
27-
var VectorWidget = React.createClass({
27+
class VectorWidget extends React.Component {
2828
/**
2929
* Initialize state members.
3030
*/
31-
getInitialState: function() {
32-
return {degrees: 0, velocity: 0, drag: MOUSE_UP_DRAG};
33-
},
31+
state = {degrees: 0, velocity: 0, drag: MOUSE_UP_DRAG};
3432

3533
/**
3634
* When the component is mounted into the document - this is similar to a
@@ -39,40 +37,40 @@ var VectorWidget = React.createClass({
3937
* method. Binding of `this.onTick` is not needed because all React methods
4038
* are automatically bound before being mounted.
4139
*/
42-
componentDidMount: function() {
40+
componentDidMount() {
4341
this._interval = window.setInterval(this.onTick, 20);
44-
},
42+
}
4543

46-
componentWillUnmount: function() {
44+
componentWillUnmount() {
4745
window.clearInterval(this._interval);
48-
},
46+
}
4947

50-
onTick: function() {
48+
onTick = () => {
5149
var nextDegrees = this.state.degrees + BASE_VEL + this.state.velocity;
5250
var nextVelocity = this.state.velocity * this.state.drag;
5351
this.setState({degrees: nextDegrees, velocity: nextVelocity});
54-
},
52+
};
5553

5654
/**
5755
* When mousing down, we increase the friction down the velocity.
5856
*/
59-
handleMouseDown: function() {
57+
handleMouseDown = () => {
6058
this.setState({drag: MOUSE_DOWN_DRAG});
61-
},
59+
};
6260

6361
/**
6462
* Cause the rotation to "spring".
6563
*/
66-
handleMouseUp: function() {
64+
handleMouseUp = () => {
6765
var nextVelocity = Math.min(this.state.velocity + CLICK_ACCEL, MAX_VEL);
6866
this.setState({velocity: nextVelocity, drag: MOUSE_UP_DRAG});
69-
},
67+
};
7068

7169
/**
7270
* This is the "main" method for any component. The React API allows you to
7371
* describe the structure of your UI component at *any* point in time.
7472
*/
75-
render: function() {
73+
render() {
7674
return (
7775
<Surface
7876
width={700}
@@ -81,12 +79,12 @@ var VectorWidget = React.createClass({
8179
{this.renderGraphic(this.state.degrees)}
8280
</Surface>
8381
);
84-
},
82+
}
8583

8684
/**
8785
* Better SVG support for React coming soon.
8886
*/
89-
renderGraphic: function(rotation) {
87+
renderGraphic = (rotation) => {
9088

9189
return (
9290
<Group
@@ -112,8 +110,8 @@ var VectorWidget = React.createClass({
112110
</Group>
113111
</Group>
114112
);
115-
}
116-
});
113+
};
114+
}
117115

118116
var BORDER_PATH = "M3.00191459,4 C1.34400294,4 0,5.34785514 0,7.00550479 L0,220.994495 C0,222.65439 1.34239483,224 3.00191459,224 L276.998085,224 C278.655997,224 280,222.652145 280,220.994495 L280,7.00550479 C280,5.34561033 278.657605,4 276.998085,4 L3.00191459,4 Z M3.00191459,4";
119117
var BG_PATH = "M3.00191459,1 C1.34400294,1 0,2.34785514 0,4.00550479 L0,217.994495 C0,219.65439 1.34239483,221 3.00191459,221 L276.998085,221 C278.655997,221 280,219.652145 280,217.994495 L280,4.00550479 C280,2.34561033 278.657605,1 276.998085,1 L3.00191459,1 Z M3.00191459,1";

fixtures/dom/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"dependencies": {
99
"classnames": "^2.2.5",
1010
"query-string": "^4.2.3",
11+
"prop-types": "^15.5.6",
1112
"react": "^15.4.1",
1213
"react-dom": "^15.4.1",
1314
"semver": "^5.3.0"

fixtures/dom/public/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Learn how to configure a non-root public URL by running `npm run build`.
1515
-->
1616
<title>React App</title>
17+
<script src="https://unpkg.com/prop-types@15.5.6/prop-types.js"></script>
1718
<script src="react-loader.js"></script>
1819
</head>
1920
<body>

fixtures/dom/src/components/App.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ import Fixtures from './fixtures';
44

55
import '../style.css';
66

7-
const App = React.createClass({
8-
render() {
9-
return (
10-
<div>
11-
<Header />
12-
<div className="container" >
13-
<Fixtures />
14-
</div>
7+
function App () {
8+
return (
9+
<div>
10+
<Header />
11+
<div className="container" >
12+
<Fixtures />
1513
</div>
16-
);
17-
},
18-
});
14+
</div>
15+
);
16+
}
1917

2018
export default App;

fixtures/dom/src/components/Fixture.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
const PropTypes = window.PropTypes;
12
const React = window.React;
23

34
const propTypes = {
4-
children: React.PropTypes.node.isRequired,
5+
children: PropTypes.node.isRequired,
56
};
67

78
class Fixture extends React.Component {

fixtures/dom/src/components/FixtureSet.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React from 'react';
2+
import PropTypes from 'prop-types';
23

34
const propTypes = {
4-
title: React.PropTypes.node.isRequired,
5-
description: React.PropTypes.node.isRequired,
5+
title: PropTypes.node.isRequired,
6+
description: PropTypes.node.isRequired,
67
};
78

89
class FixtureSet extends React.Component {

fixtures/dom/src/components/Header.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,33 @@ import { parse, stringify } from 'query-string';
22
import getVersionTags from '../tags';
33
const React = window.React;
44

5-
const Header = React.createClass({
6-
getInitialState() {
5+
class Header extends React.Component {
6+
constructor(props, context) {
7+
super(props, context);
78
const query = parse(window.location.search);
89
const version = query.version || 'local';
910
const versions = [version];
10-
return { version, versions };
11-
},
11+
this.state = { version, versions };
12+
}
1213
componentWillMount() {
1314
getVersionTags()
1415
.then(tags => {
1516
let versions = tags.map(tag => tag.name.slice(1));
1617
versions = [`local`, ...versions];
1718
this.setState({ versions });
1819
})
19-
},
20+
}
2021
handleVersionChange(event) {
2122
const query = parse(window.location.search);
2223
query.version = event.target.value;
2324
if (query.version === 'local') {
2425
delete query.version;
2526
}
2627
window.location.search = stringify(query);
27-
},
28+
}
2829
handleFixtureChange(event) {
2930
window.location.pathname = event.target.value;
30-
},
31+
}
3132
render() {
3233
return (
3334
<header className="header">
@@ -66,7 +67,7 @@ const Header = React.createClass({
6667
</div>
6768
</header>
6869
);
69-
},
70-
});
70+
}
71+
}
7172

7273
export default Header;

fixtures/dom/src/components/TestCase.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import cn from 'classnames';
22
import semver from 'semver';
33
import React from 'react';
4+
import PropTypes from 'prop-types';
45
import { parse } from 'query-string';
5-
import { semverString } from './propTypes'
6+
import { semverString } from './propTypes';
67

78
const propTypes = {
8-
children: React.PropTypes.node.isRequired,
9-
title: React.PropTypes.node.isRequired,
9+
children: PropTypes.node.isRequired,
10+
title: PropTypes.node.isRequired,
1011
resolvedIn: semverString,
11-
resolvedBy: React.PropTypes.string
12+
resolvedBy: PropTypes.string
1213
};
1314

1415
class TestCase extends React.Component {

fixtures/dom/src/components/fixtures/buttons/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function onButtonClick() {
1010
export default class ButtonTestCases extends React.Component {
1111
render() {
1212
return (
13-
<FixtureSet title="Buttons">
13+
<FixtureSet title="Buttons" description="">
1414
<TestCase
1515
title="onClick with disabled buttons"
1616
description="The onClick event handler should not be invoked when clicking on a disabled buyaton">

fixtures/dom/src/components/fixtures/index.js

+22-24
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,27 @@ import ButtonFixtures from './buttons';
1212
* A simple routing component that renders the appropriate
1313
* fixture based on the location pathname.
1414
*/
15-
const FixturesPage = React.createClass({
16-
render() {
17-
switch (window.location.pathname) {
18-
case '/text-inputs':
19-
return <TextInputFixtures />;
20-
case '/range-inputs':
21-
return <RangeInputFixtures />;
22-
case '/selects':
23-
return <SelectFixtures />;
24-
case '/textareas':
25-
return <TextAreaFixtures />;
26-
case '/input-change-events':
27-
return <InputChangeEvents />;
28-
case '/number-inputs':
29-
return <NumberInputFixtures />;
30-
case '/password-inputs':
31-
return <PasswordInputFixtures />;
32-
case '/buttons':
33-
return <ButtonFixtures />
34-
default:
35-
return <p>Please select a test fixture.</p>;
36-
}
37-
},
38-
});
15+
function FixturesPage() {
16+
switch (window.location.pathname) {
17+
case '/text-inputs':
18+
return <TextInputFixtures />;
19+
case '/range-inputs':
20+
return <RangeInputFixtures />;
21+
case '/selects':
22+
return <SelectFixtures />;
23+
case '/textareas':
24+
return <TextAreaFixtures />;
25+
case '/input-change-events':
26+
return <InputChangeEvents />;
27+
case '/number-inputs':
28+
return <NumberInputFixtures />;
29+
case '/password-inputs':
30+
return <PasswordInputFixtures />;
31+
case '/buttons':
32+
return <ButtonFixtures />
33+
default:
34+
return <p>Please select a test fixture.</p>;
35+
}
36+
}
3937

4038
module.exports = FixturesPage;

fixtures/dom/src/components/fixtures/number-inputs/NumberTestCase.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ const React = window.React;
22

33
import Fixture from '../../Fixture';
44

5-
const NumberTestCase = React.createClass({
6-
getInitialState() {
7-
return { value: '' };
8-
},
9-
onChange(event) {
5+
class NumberTestCase extends React.Component {
6+
state = { value: '' };
7+
onChange = (event) => {
108
const parsed = parseFloat(event.target.value, 10)
119
const value = isNaN(parsed) ? '' : parsed
1210

1311
this.setState({ value })
14-
},
12+
}
1513
render() {
1614
return (
1715
<Fixture>
@@ -31,7 +29,7 @@ const NumberTestCase = React.createClass({
3129
</div>
3230
</Fixture>
3331
);
34-
},
35-
});
32+
}
33+
}
3634

3735
export default NumberTestCase;

0 commit comments

Comments
 (0)