Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build process for createReactClass #9943

Merged
merged 4 commits into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
'dot-notation': ERROR,
'eol-last': ERROR,
'eqeqeq': [ERROR, 'allow-null'],
'indent': [ERROR, 2, {SwitchCase: 1}],
'indent': OFF, // We use Prettier now
'jsx-quotes': [ERROR, 'prefer-double'],
'keyword-spacing': [ERROR, {after: true, before: true}],
'no-bitwise': OFF,
Expand Down
2 changes: 2 additions & 0 deletions addons/create-react-class/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
create-react-class.js
create-react-class.min.js
46 changes: 23 additions & 23 deletions addons/create-react-class/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
Constructor.childContextTypes = _assign(
{},
Constructor.childContextTypes,
childContextTypes,
childContextTypes
);
},
contextTypes: function(Constructor, contextTypes) {
Expand All @@ -324,7 +324,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
Constructor.contextTypes = _assign(
{},
Constructor.contextTypes,
contextTypes,
contextTypes
);
},
/**
Expand All @@ -335,7 +335,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
if (Constructor.getDefaultProps) {
Constructor.getDefaultProps = createMergedResultFunction(
Constructor.getDefaultProps,
getDefaultProps,
getDefaultProps
);
} else {
Constructor.getDefaultProps = getDefaultProps;
Expand Down Expand Up @@ -365,7 +365,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
'React.PropTypes.',
Constructor.displayName || 'ReactClass',
ReactPropTypeLocationNames[location],
propName,
propName
);
}
}
Expand All @@ -384,7 +384,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
'ReactClassInterface: You are attempting to override ' +
'`%s` from your class specification. Ensure that your method names ' +
'do not overlap with React methods.',
name,
name
);
}

Expand All @@ -395,7 +395,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
'ReactClassInterface: You are attempting to define ' +
'`%s` on your component more than once. This conflict may be due ' +
'to a mixin.',
name,
name
);
}
}
Expand All @@ -418,7 +418,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
'as well as any mixins they include themselves. ' +
'Expected object but got %s.',
Constructor.displayName || 'ReactClass',
spec === null ? null : typeofSpec,
spec === null ? null : typeofSpec
);
}
}
Expand All @@ -430,12 +430,12 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
typeof spec !== 'function',
"ReactClass: You're attempting to " +
'use a component class or function as a mixin. Instead, just use a ' +
'regular object.',
'regular object.'
);
_invariant(
!isValidElement(spec),
"ReactClass: You're attempting to " +
'use a component as a mixin. Instead, just use a regular object.',
'use a component as a mixin. Instead, just use a regular object.'
);

var proto = Constructor.prototype;
Expand Down Expand Up @@ -492,7 +492,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
'ReactClass: Unexpected spec policy %s for key %s ' +
'when mixing in component specs.',
specPolicy,
name,
name
);

// For methods which are defined more than once, call the existing
Expand Down Expand Up @@ -534,7 +534,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
'property, `%s`, that shouldn\'t be on the "statics" key. Define it ' +
'as an instance property instead; it will still be accessible on the ' +
'constructor.',
name,
name
);

var isInherited = name in Constructor;
Expand All @@ -543,7 +543,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
'ReactClass: You are attempting to define ' +
'`%s` on your component more than once. This conflict may be ' +
'due to a mixin.',
name,
name
);
Constructor[name] = property;
}
Expand All @@ -559,7 +559,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
function mergeIntoWithNoDuplicateKeys(one, two) {
_invariant(
one && two && typeof one === 'object' && typeof two === 'object',
'mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.',
'mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.'
);

for (var key in two) {
Expand All @@ -571,7 +571,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
'may be due to a mixin; in particular, this may be caused by two ' +
'getInitialState() or getDefaultProps() methods returning objects ' +
'with clashing keys.',
key,
key
);
one[key] = two[key];
}
Expand Down Expand Up @@ -653,7 +653,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
false,
'bind(): React component methods may only be bound to the ' +
'component instance. See %s',
componentName,
componentName
);
}
} else if (!args.length) {
Expand All @@ -663,7 +663,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
'bind(): You are binding a component method to the component. ' +
'React does this for you automatically in a high-performance ' +
'way, so you can safely remove this call. See %s',
componentName,
componentName
);
}
return boundMethod;
Expand Down Expand Up @@ -732,7 +732,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
'prevent memory leaks.',
(this.constructor && this.constructor.displayName) ||
this.name ||
'Component',
'Component'
);
this.__didWarnIsMounted = true;
}
Expand All @@ -744,7 +744,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
_assign(
ReactClassComponent.prototype,
ReactComponent.prototype,
ReactClassMixin,
ReactClassMixin
);

/**
Expand All @@ -767,7 +767,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
warning(
this instanceof Constructor,
'Something is calling a React component directly. Use a factory or ' +
'JSX instead. See: https://fb.me/react-legacyfactory',
'JSX instead. See: https://fb.me/react-legacyfactory'
);
}

Expand Down Expand Up @@ -801,7 +801,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
_invariant(
typeof initialState === 'object' && !Array.isArray(initialState),
'%s.getInitialState(): must return an object or null',
Constructor.displayName || 'ReactCompositeComponent',
Constructor.displayName || 'ReactCompositeComponent'
);

this.state = initialState;
Expand Down Expand Up @@ -836,7 +836,7 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {

_invariant(
Constructor.prototype.render,
'createClass(...): Class specification must implement a `render` method.',
'createClass(...): Class specification must implement a `render` method.'
);

if (process.env.NODE_ENV !== 'production') {
Expand All @@ -846,13 +846,13 @@ function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' +
'The name is phrased as a question because the function is ' +
'expected to return a value.',
spec.displayName || 'A component',
spec.displayName || 'A component'
);
warning(
!Constructor.prototype.componentWillRecieveProps,
'%s has a method called ' +
'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?',
spec.displayName || 'A component',
spec.displayName || 'A component'
);
}

Expand Down
9 changes: 8 additions & 1 deletion addons/create-react-class/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@
var React = require('react');
var factory = require('./factory');

if (typeof React === 'undefined') {
throw Error(
'createReactClass could not find the React object. If you are using script tags, ' +
'make sure that React is being loaded before createReactClass.'
);
}

// Hack to grab NoopUpdateQueue from isomorphic React
var ReactNoopUpdateQueue = new React.Component().updater;

module.exports = factory(
React.Component,
React.isValidElement,
ReactNoopUpdateQueue,
ReactNoopUpdateQueue
);
13 changes: 9 additions & 4 deletions addons/create-react-class/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@
"object-assign": "^4.1.1"
},
"scripts": {
"test": "jest"
"test": "TEST_ENTRY=./index.js jest",
"build:dev": "NODE_ENV=development webpack && TEST_ENTRY=./create-react-class.js jest",
"build:prod": "NODE_ENV=production webpack && NODE_ENV=production TEST_ENTRY=./create-react-class.min.js jest",
"build": "npm run build:dev && npm run build:prod",
"prepublish": "npm test && npm run build"
},
"devDependencies": {
"jest": "^19.0.2",
"react": "^15.5.0",
"react-addons-test-utils": "^15.5.0",
"react-dom": "^15.5.0"
"prop-types": "^15.5.10",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"webpack": "^2.6.1"
},
"browserify": {
"transform": [
Expand Down