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

Remove "construct" call except on composites

This is a little simpler (and a teeny tiny bit faster). The one in ReactCompositeComponent stays because of the way we create ReactCompositeComponentWrapper inside instantiateReactComponent.

Ben Alpert committed Sep 22, 2015 at 12:08 UTC acb49363d5eaa69042d6e895e9246c7d606711bd
7 files changed +22 -39
src/renderers/dom/shared/ReactDOMComponent.js
+3 -5
@@ -405,8 +405,10 @@ var globalIdCounter = 1;
405 * @constructor ReactDOMComponent
406 * @extends ReactMultiChild
407 */
408 -function ReactDOMComponent(tag) {
408 +function ReactDOMComponent(element) {
409 + var tag = element.type;
410 validateDangerousTag(tag);
411 + this._currentElement = element;
412 this._tag = tag.toLowerCase();
413 this._namespaceURI = null;
414 this._renderedChildren = null;
@@ -429,10 +431,6 @@ ReactDOMComponent.displayName = 'ReactDOMComponent';
431
432 ReactDOMComponent.Mixin = {
433
432 - construct: function(element) {
433 - this._currentElement = element;
434 - },
435 -
434 /**
435 * Generates root tag markup then recurses. This method has side effects and
436 * is not idempotent.
src/renderers/dom/shared/ReactDOMEmptyComponent.js
-2
@@ -26,8 +26,6 @@ var ReactDOMEmptyComponent = function(instantiate) {
26 this._domID = null;
27 };
28 assign(ReactDOMEmptyComponent.prototype, {
29 - construct: function(element) {
30 - },
29 mountComponent: function(
30 transaction,
31 nativeParent,
src/renderers/dom/shared/ReactDOMTextComponent.js
+11 -19
@@ -38,29 +38,21 @@ var getNode = ReactDOMComponentTree.getNodeFromInstance;
38 * @extends ReactComponent
39 * @internal
40 */
41 -var ReactDOMTextComponent = function(props) {
42 - // This constructor and its argument is currently used by mocks.
41 +var ReactDOMTextComponent = function(text) {
42 + // TODO: This is really a ReactText (ReactNode), not a ReactElement
43 + this._currentElement = text;
44 + this._stringText = '' + text;
45 + // ReactDOMComponentTree uses these:
46 + this._nativeNode = null;
47 + this._nativeParent = null;
48 +
49 + // Properties
50 + this._domID = null;
51 + this._mountIndex = 0;
52 };
53
54 assign(ReactDOMTextComponent.prototype, {
55
47 - /**
48 - * @param {ReactText} text
49 - * @internal
50 - */
51 - construct: function(text) {
52 - // TODO: This is really a ReactText (ReactNode), not a ReactElement
53 - this._currentElement = text;
54 - this._stringText = '' + text;
55 - // ReactDOMComponentTree uses these:
56 - this._nativeNode = null;
57 - this._nativeParent = null;
58 -
59 - // Properties
60 - this._domID = null;
61 - this._mountIndex = 0;
62 - },
63 -
56 /**
57 * Creates the markup for this text node. This node is not intended to have
58 * any features besides containing text content.
src/renderers/shared/reconciler/ReactNativeComponent.js
+1 -1
@@ -68,7 +68,7 @@ function createInternalComponent(element) {
68 'There is no registered component for the tag %s',
69 element.type
70 );
71 - return new genericComponentClass(element.type, element.props);
71 + return new genericComponentClass(element);
72 }
73
74 /**
src/renderers/shared/reconciler/ReactSimpleEmptyComponent.js
-2
@@ -20,8 +20,6 @@ var ReactSimpleEmptyComponent = function(placeholderElement, instantiate) {
20 this._renderedComponent = instantiate(placeholderElement);
21 };
22 assign(ReactSimpleEmptyComponent.prototype, {
23 - construct: function(element) {
24 - },
23 mountComponent: function(
24 transaction,
25 nativeParent,
src/renderers/shared/reconciler/instantiateReactComponent.js
+4 -6
@@ -20,7 +20,9 @@ var invariant = require('invariant');
20 var warning = require('warning');
21
22 // To avoid a cyclic dependency, we create the final class in this module
23 -var ReactCompositeComponentWrapper = function() { };
23 +var ReactCompositeComponentWrapper = function(element) {
24 + this.construct(element);
25 +};
26 assign(
27 ReactCompositeComponentWrapper.prototype,
28 ReactCompositeComponent.Mixin,
@@ -87,7 +89,7 @@ function instantiateReactComponent(node) {
89 // representation, we can drop this code path.
90 instance = new element.type(element);
91 } else {
90 - instance = new ReactCompositeComponentWrapper();
92 + instance = new ReactCompositeComponentWrapper(element);
93 }
94 } else if (typeof node === 'string' || typeof node === 'number') {
95 instance = ReactNativeComponent.createInstanceForText(node);
@@ -101,7 +103,6 @@ function instantiateReactComponent(node) {
103
104 if (__DEV__) {
105 warning(
104 - typeof instance.construct === 'function' &&
106 typeof instance.mountComponent === 'function' &&
107 typeof instance.receiveComponent === 'function' &&
108 typeof instance.getNativeNode === 'function' &&
@@ -110,9 +111,6 @@ function instantiateReactComponent(node) {
111 );
112 }
113
113 - // Sets up the instance. This can probably just move into the constructor now.
114 - instance.construct(node);
115 -
114 // These two fields are used by the DOM and ART diffing algorithms
115 // respectively. Instead of using expandos on components, we should be
116 // storing the state needed by the diffing algorithms elsewhere.
src/test/ReactTestUtils.js
+3 -4
@@ -393,7 +393,9 @@ NoopInternalComponent.prototype = {
393 },
394 };
395
396 -var ShallowComponentWrapper = function() { };
396 +var ShallowComponentWrapper = function(element) {
397 + this.construct(element);
398 +};
399 assign(
400 ShallowComponentWrapper.prototype,
401 ReactCompositeComponent.Mixin, {
@@ -457,10 +459,7 @@ ReactShallowRenderer.prototype._render = function(element, transaction, context)
459 this._instance.receiveComponent(element, transaction, context);
460 } else {
461 var instance = new ShallowComponentWrapper(element.type);
460 - instance.construct(element);
461 -
462 instance.mountComponent(transaction, null, null, context);
463 -
463 this._instance = instance;
464 }
465 };