@samitouri / QOS-React-2 / commits / c136369a81

Remove prop types checking in ReactCompositeComponent (#6824)

Remove prop types checking in ReactCompositeComponent

Keyan Zhang committed May 23, 2016 at 11:13 UTC c136369a811b591e537038106c9c034625f0c3ee
2 files changed +19 -58
src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
+3 -3
@@ -849,9 +849,8 @@ describe('ReactPropTypes', function() {
849 var instance = <Component num={5} />;
850 instance = ReactTestUtils.renderIntoDocument(instance);
851
852 - expect(spy.argsForCall.length).toBe(2); // temp double validation
852 + expect(spy.argsForCall.length).toBe(1);
853 expect(spy.argsForCall[0][1]).toBe('num');
854 - expect(spy.argsForCall[0][2]).toBe('Component');
854 });
855
856 it('should have been called even if the prop is not present', function() {
@@ -867,7 +866,8 @@ describe('ReactPropTypes', function() {
866 var instance = <Component bla={5} />;
867 instance = ReactTestUtils.renderIntoDocument(instance);
868
870 - expect(spy.argsForCall.length).toBe(2); // temp double validation
869 + expect(spy.argsForCall.length).toBe(1);
870 + expect(spy.argsForCall[0][1]).toBe('num');
871 });
872
873 it('should have received the validator\'s return value', function() {
src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
+16 -55
@@ -197,7 +197,7 @@ var ReactCompositeComponentMixin = {
197 this._hostParent = hostParent;
198 this._hostContainerInfo = hostContainerInfo;
199
200 - var publicProps = this._processProps(this._currentElement.props);
200 + var publicProps = this._currentElement.props;
201 var publicContext = this._processContext(context);
202
203 var Component = this._currentElement.type;
@@ -614,7 +614,7 @@ var ReactCompositeComponentMixin = {
614 if (__DEV__) {
615 var Component = this._currentElement.type;
616 if (Component.contextTypes) {
617 - this._checkPropTypes(
617 + this._checkContextTypes(
618 Component.contextTypes,
619 maskedContext,
620 ReactPropTypeLocations.context
@@ -647,7 +647,7 @@ var ReactCompositeComponentMixin = {
647 this.getName() || 'ReactCompositeComponent'
648 );
649 if (__DEV__) {
650 - this._checkPropTypes(
650 + this._checkContextTypes(
651 Component.childContextTypes,
652 childContext,
653 ReactPropTypeLocations.childContext
@@ -667,39 +667,14 @@ var ReactCompositeComponentMixin = {
667 },
668
669 /**
670 - * Processes props by setting default values for unspecified props and
671 - * asserting that the props are valid. Does not mutate its argument; returns
672 - * a new props object with defaults merged in.
670 + * Assert that the context types are valid
671 *
674 - * @param {object} newProps
675 - * @return {object}
676 - * @private
677 - */
678 - _processProps: function(newProps) {
679 - if (__DEV__) {
680 - var Component = this._currentElement.type;
681 - if (Component.propTypes) {
682 - this._checkPropTypes(
683 - Component.propTypes,
684 - newProps,
685 - ReactPropTypeLocations.prop
686 - );
687 - }
688 - }
689 - return newProps;
690 - },
691 -
692 - /**
693 - * Assert that the props are valid
694 - *
695 - * @param {object} propTypes Map of prop name to a ReactPropType
672 + * @param {object} propTypes Map of context field to a ReactPropType
673 * @param {object} props
674 * @param {string} location e.g. "prop", "context", "child context"
675 * @private
676 */
700 - _checkPropTypes: function(propTypes, props, location) {
701 - // TODO: Stop validating prop types here and only use the element
702 - // validation.
677 + _checkContextTypes: function(propTypes, props, location) {
678 var componentName = this.getName();
679 for (var propName in propTypes) {
680 if (propTypes.hasOwnProperty(propName)) {
@@ -724,23 +699,12 @@ var ReactCompositeComponentMixin = {
699 // top-level render calls, so I'm abstracting it away into
700 // a function to minimize refactoring in the future
701 var addendum = getDeclarationErrorAddendum(this);
727 -
728 - if (location === ReactPropTypeLocations.prop) {
729 - // Preface gives us something to blacklist in warning module
730 - warning(
731 - false,
732 - 'Failed Composite propType: %s%s',
733 - error.message,
734 - addendum
735 - );
736 - } else {
737 - warning(
738 - false,
739 - 'Failed Context Types: %s%s',
740 - error.message,
741 - addendum
742 - );
743 - }
702 + warning(
703 + false,
704 + 'Failed Context Types: %s%s',
705 + error.message,
706 + addendum
707 + );
708 }
709 }
710 }
@@ -824,13 +788,10 @@ var ReactCompositeComponentMixin = {
788 willReceive = true;
789 }
790
827 - // Distinguish between a props update versus a simple state update
828 - if (prevParentElement === nextParentElement) {
829 - // Skip checking prop types again -- we don't read inst.props to avoid
830 - // warning for DOM component props in this upgrade
831 - nextProps = nextParentElement.props;
832 - } else {
833 - nextProps = this._processProps(nextParentElement.props);
791 + nextProps = nextParentElement.props;
792 +
793 + // Not a simple state update but a props update
794 + if (prevParentElement !== nextParentElement) {
795 willReceive = true;
796 }
797