MCPcopy Create free account
hub / github.com/reactjs/react-rails / createClass

Function createClass

lib/assets/react-source/development/react.js:30016–30131  ·  view source on GitHub ↗

* Creates a composite component class given a class specification. * See https://facebook.github.io/react/docs/top-level-api.html#react.createclass * * @param {object} spec Class specification (which must define `render`). * @return {function} Component constructor function. * @p

(spec)

Source from the content-addressed store, hash-verified

30014 * @public
30015 */
30016 function createClass(spec) {
30017 // To keep our warnings more understandable, we'll use a little hack here to
30018 // ensure that Constructor.name !== 'Constructor'. This makes sure we don't
30019 // unnecessarily identify a class without displayName as 'Constructor'.
30020 var Constructor = identity(function(props, context, updater) {
30021 // This constructor gets overridden by mocks. The argument is used
30022 // by mocks to assert on what gets mounted.
30023
30024 if (process.env.NODE_ENV !== 'production') {
30025 warning(
30026 this instanceof Constructor,
30027 'Something is calling a React component directly. Use a factory or ' +
30028 'JSX instead. See: https://fb.me/react-legacyfactory'
30029 );
30030 }
30031
30032 // Wire up auto-binding
30033 if (this.__reactAutoBindPairs.length) {
30034 bindAutoBindMethods(this);
30035 }
30036
30037 this.props = props;
30038 this.context = context;
30039 this.refs = emptyObject;
30040 this.updater = updater || ReactNoopUpdateQueue;
30041
30042 this.state = null;
30043
30044 // ReactClasses doesn't have constructors. Instead, they use the
30045 // getInitialState and componentWillMount methods for initialization.
30046
30047 var initialState = this.getInitialState ? this.getInitialState() : null;
30048 if (process.env.NODE_ENV !== 'production') {
30049 // We allow auto-mocks to proceed as if they're returning null.
30050 if (
30051 initialState === undefined &&
30052 this.getInitialState._isMockFunction
30053 ) {
30054 // This is probably bad practice. Consider warning here and
30055 // deprecating this convenience.
30056 initialState = null;
30057 }
30058 }
30059 _invariant(
30060 typeof initialState === 'object' && !Array.isArray(initialState),
30061 '%s.getInitialState(): must return an object or null',
30062 Constructor.displayName || 'ReactCompositeComponent'
30063 );
30064
30065 this.state = initialState;
30066 });
30067 Constructor.prototype = new ReactClassComponent();
30068 Constructor.prototype.constructor = Constructor;
30069 Constructor.prototype.__reactAutoBindPairs = [];
30070
30071 injectedMixins.forEach(mixSpecIntoComponent.bind(null, Constructor));
30072
30073 mixSpecIntoComponent(Constructor, IsMountedPreMixin);

Callers

nothing calls this directly

Calls 5

identityFunction · 0.70
warningFunction · 0.70
bindAutoBindMethodsFunction · 0.70
_invariantFunction · 0.70
mixSpecIntoComponentFunction · 0.70

Tested by

no test coverage detected