Skip to content

Commit

Permalink
Added createClass and PropTypes getters (w/ depreaction warnings) to …
Browse files Browse the repository at this point in the history
…React
  • Loading branch information
Brian Vaughn committed Apr 11, 2017
1 parent ef5b5c6 commit 524ce20
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 866 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"coffee-script": "^1.8.0",
"core-js": "^2.2.1",
"coveralls": "^2.11.6",
"create-react-class": "^15.5.0",
"del": "^2.0.2",
"derequire": "^2.0.3",
"escape-string-regexp": "^1.0.5",
Expand Down Expand Up @@ -73,7 +72,6 @@
"object-assign": "^4.1.1",
"platform": "^1.1.0",
"prettier": "^0.22.0",
"prop-types": "^15.5.6",
"rimraf": "^2.6.1",
"rollup": "^0.41.6",
"rollup-plugin-alias": "^1.2.1",
Expand All @@ -95,6 +93,10 @@
"node": "4.x || 5.x || 6.x || 7.x",
"npm": "2.x || 3.x || 4.x"
},
"dependencies": {
"create-react-class": "^15.5.2",
"prop-types": "^15.5.6"
},
"commonerConfig": {
"version": 7
},
Expand Down
7 changes: 6 additions & 1 deletion scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ const bundles = [
sourceMap: false,
},
entry: 'src/isomorphic/React.js',
externals: [],
externals: [
'create-react-class/factory',
'prop-types',
'prop-types/checkPropTypes',
'prop-types/factory',
],
fbEntry: 'src/fb/ReactFBEntry.js',
hasteName: 'React',
isRenderer: false,
Expand Down
26 changes: 13 additions & 13 deletions scripts/rollup/results.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"branch": null,
"branch": "prop-types",
"bundleSizes": {
"react.development.js (UMD_DEV)": {
"size": 92740,
"gzip": 23440
"size": 76661,
"gzip": 19565
},
"react.production.min.js (UMD_PROD)": {
"size": 10409,
"gzip": 4091
"size": 10467,
"gzip": 4074
},
"react-dom.development.js (UMD_DEV)": {
"size": 563910,
Expand All @@ -34,20 +34,20 @@
"gzip": 28991
},
"react.development.js (NODE_DEV)": {
"size": 85810,
"gzip": 21432
"size": 69636,
"gzip": 17533
},
"react.production.min.js (NODE_PROD)": {
"size": 9288,
"gzip": 3659
"size": 9226,
"gzip": 3623
},
"React-dev.js (FB_DEV)": {
"size": 87652,
"gzip": 22071
"size": 71493,
"gzip": 18168
},
"React-prod.js (FB_PROD)": {
"size": 37663,
"gzip": 9519
"size": 36701,
"gzip": 9254
},
"ReactDOMStack-dev.js (FB_DEV)": {
"size": 522667,
Expand Down
20 changes: 18 additions & 2 deletions src/isomorphic/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var ReactVersion = require('ReactVersion');

var onlyChild = require('onlyChild');
var checkPropTypes = require('checkPropTypes');
var createReactClass = require('createClass');

var createElement = ReactElement.createElement;
var createFactory = ReactElement.createFactory;
Expand All @@ -28,6 +29,7 @@ var cloneElement = ReactElement.cloneElement;
if (__DEV__) {
var warning = require('fbjs/lib/warning');
var canDefineProperty = require('canDefineProperty');
var didWarnPropTypesDeprecated = false;
var ReactElementValidator = require('ReactElementValidator');
createElement = ReactElementValidator.createElement;
createFactory = ReactElementValidator.createFactory;
Expand Down Expand Up @@ -60,7 +62,8 @@ var React = {

// Classic

PropTypes: ReactPropTypes,
PropTypes: ReactPropTypes, // TODO (bvaughn) Remove this getter in 16.0.0-alpha.10
createClass: createReactClass, // TODO (bvaughn) Remove this getter in 16.0.0-alpha.10
createFactory: createFactory,
createMixin: createMixin,

Expand Down Expand Up @@ -95,6 +98,7 @@ if (__DEV__) {
return mixin;
};

// TODO (bvaughn) Remove both of these deprecation warnings in 16.0.0-alpha.10
if (canDefineProperty) {
Object.defineProperty(React, 'createClass', {
get: function() {
Expand All @@ -106,7 +110,19 @@ if (__DEV__) {
'drop-in replacement.',
);
warnedForCreateClass = true;
return undefined;
return createReactClass;
},
});

Object.defineProperty(React, 'PropTypes', {
get() {
warning(
didWarnPropTypesDeprecated,
'PropTypes have moved out of the react package. ' +
'Use the prop-types package from npm instead.',
);
didWarnPropTypesDeprecated = true;
return ReactPropTypes;
},
});
}
Expand Down
14 changes: 13 additions & 1 deletion src/isomorphic/__tests__/React-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('React', () => {
spyOn(console, 'error');
let createClass = React.createClass;
createClass = React.createClass;
expect(createClass).toBe(undefined);
expect(createClass).not.toBe(undefined);
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'React.createClass is no longer supported. Use a plain ' +
Expand All @@ -41,4 +41,16 @@ describe('React', () => {
'drop-in replacement.',
);
});

it('should warn once when attempting to access React.PropTypes', () => {
spyOn(console, 'error');
let PropTypes = React.PropTypes;
PropTypes = React.PropTypes;
expect(PropTypes).not.toBe(undefined);
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'PropTypes have moved out of the react package. ' +
'Use the prop-types package from npm instead.',
);
});
});
19 changes: 19 additions & 0 deletions src/isomorphic/classic/class/createClass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule createClass
*/

'use strict';

var {Component} = require('ReactBaseClasses');
var {isValidElement} = require('ReactElement');
var ReactNoopUpdateQueue = require('ReactNoopUpdateQueue');
var factory = require('create-react-class/factory');

module.exports = factory(Component, isValidElement, ReactNoopUpdateQueue);
Loading

0 comments on commit 524ce20

Please sign in to comment.