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

Function mixSpecIntoComponent

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

* Mixin helper which handles policy validation and reserved * specification keys when building React classes.

(Constructor, spec)

Source from the content-addressed store, hash-verified

29651 * specification keys when building React classes.
29652 */
29653 function mixSpecIntoComponent(Constructor, spec) {
29654 if (!spec) {
29655 if (process.env.NODE_ENV !== 'production') {
29656 var typeofSpec = typeof spec;
29657 var isMixinValid = typeofSpec === 'object' && spec !== null;
29658
29659 if (process.env.NODE_ENV !== 'production') {
29660 warning(
29661 isMixinValid,
29662 "%s: You're attempting to include a mixin that is either null " +
29663 'or not an object. Check the mixins included by the component, ' +
29664 'as well as any mixins they include themselves. ' +
29665 'Expected object but got %s.',
29666 Constructor.displayName || 'ReactClass',
29667 spec === null ? null : typeofSpec
29668 );
29669 }
29670 }
29671
29672 return;
29673 }
29674
29675 _invariant(
29676 typeof spec !== 'function',
29677 "ReactClass: You're attempting to " +
29678 'use a component class or function as a mixin. Instead, just use a ' +
29679 'regular object.'
29680 );
29681 _invariant(
29682 !isValidElement(spec),
29683 "ReactClass: You're attempting to " +
29684 'use a component as a mixin. Instead, just use a regular object.'
29685 );
29686
29687 var proto = Constructor.prototype;
29688 var autoBindPairs = proto.__reactAutoBindPairs;
29689
29690 // By handling mixins before any other properties, we ensure the same
29691 // chaining order is applied to methods with DEFINE_MANY policy, whether
29692 // mixins are listed before or after these methods in the spec.
29693 if (spec.hasOwnProperty(MIXINS_KEY)) {
29694 RESERVED_SPEC_KEYS.mixins(Constructor, spec.mixins);
29695 }
29696
29697 for (var name in spec) {
29698 if (!spec.hasOwnProperty(name)) {
29699 continue;
29700 }
29701
29702 if (name === MIXINS_KEY) {
29703 // We have already handled mixins in a special case above.
29704 continue;
29705 }
29706
29707 var property = spec[name];
29708 var isAlreadyDefined = proto.hasOwnProperty(name);
29709 validateMethodOverride(isAlreadyDefined, name);
29710

Callers 2

factoryFunction · 0.70
createClassFunction · 0.70

Calls 6

warningFunction · 0.70
_invariantFunction · 0.70
isValidElementFunction · 0.70
validateMethodOverrideFunction · 0.70
createChainedFunctionFunction · 0.70

Tested by

no test coverage detected