@samitouri / QOS-React / commits / a9e0896af8

Mute devtool events for TopLevelWrapper and empty components

Dan Abramov committed Apr 26, 2016 at 01:01 UTC a9e0896af88bd42401ea76eb1c97376f492682a0
6 files changed +36 -53
src/isomorphic/ReactDebugTool.js
+4 -20
@@ -37,11 +37,6 @@ function emitEvent(handlerFunctionName, arg1, arg2, arg3, arg4, arg5) {
37 }
38 }
39
40 -// This can be removed once TopLevelWrapper is gone.
41 -function isTopLevelWrapper(debugID) {
42 - return debugID === 0;
43 -}
44 -
40 var ReactDebugTool = {
41 addDevtool(devtool) {
42 eventHandlers.push(devtool);
@@ -66,13 +61,8 @@ var ReactDebugTool = {
61 onSetDisplayName(debugID, displayName) {
62 emitEvent('onSetDisplayName', debugID, displayName);
63 },
69 - onSetIsEmpty(debugID, isEmpty) {
70 - emitEvent('onSetIsEmpty', debugID, isEmpty);
71 - },
64 onSetChildren(debugID, childDebugIDs) {
73 - if (!isTopLevelWrapper(debugID)) {
74 - emitEvent('onSetChildren', debugID, childDebugIDs);
75 - }
65 + emitEvent('onSetChildren', debugID, childDebugIDs);
66 },
67 onSetOwner(debugID, ownerDebugID) {
68 emitEvent('onSetOwner', debugID, ownerDebugID);
@@ -84,19 +74,13 @@ var ReactDebugTool = {
74 emitEvent('onMountRootComponent', debugID);
75 },
76 onMountComponent(debugID) {
87 - if (!isTopLevelWrapper(debugID)) {
88 - emitEvent('onMountComponent', debugID);
89 - }
77 + emitEvent('onMountComponent', debugID);
78 },
79 onUpdateComponent(debugID) {
92 - if (!isTopLevelWrapper(debugID)) {
93 - emitEvent('onUpdateComponent', debugID);
94 - }
80 + emitEvent('onUpdateComponent', debugID);
81 },
82 onUnmountComponent(debugID) {
97 - if (!isTopLevelWrapper(debugID)) {
98 - emitEvent('onUnmountComponent', debugID);
99 - }
83 + emitEvent('onUnmountComponent', debugID);
84 },
85 };
86
src/isomorphic/devtools/ReactComponentTreeDevtool.js
+1 -6
@@ -25,7 +25,6 @@ function updateTree(id, update) {
25 childIDs: [],
26 displayName: 'Unknown',
27 isMounted: false,
28 - isEmpty: false,
28 };
29 }
30 update(tree[id]);
@@ -41,10 +40,6 @@ function purgeDeep(id) {
40 }
41
42 var ReactComponentTreeDevtool = {
44 - onSetIsEmpty(id, isEmpty) {
45 - updateTree(id, item => item.isEmpty = isEmpty);
46 - },
47 -
43 onSetDisplayName(id, displayName) {
44 updateTree(id, item => item.displayName = displayName);
45 },
@@ -118,7 +113,7 @@ var ReactComponentTreeDevtool = {
113
114 getChildIDs(id) {
115 var item = tree[id];
121 - return item ? item.childIDs.filter(childID => !tree[childID].isEmpty) : [];
116 + return item ? item.childIDs : [];
117 },
118
119 getDisplayName(id) {
src/renderers/dom/shared/ReactDOMComponent.js
-1
@@ -253,7 +253,6 @@ if (__DEV__) {
253 var debugID = this._debugID;
254 var contentDebugID = debugID + '#text';
255 this._contentDebugID = contentDebugID;
256 - ReactInstrumentation.debugTool.onSetIsEmpty(contentDebugID, false);
256 ReactInstrumentation.debugTool.onSetDisplayName(contentDebugID, '#text');
257 ReactInstrumentation.debugTool.onSetText(contentDebugID, '' + contentToUse);
258 ReactInstrumentation.debugTool.onMountComponent(contentDebugID);
src/renderers/shared/reconciler/ReactCompositeComponent.js
+16 -8
@@ -387,10 +387,14 @@ var ReactCompositeComponentMixin = {
387 );
388
389 if (__DEV__) {
390 - ReactInstrumentation.debugTool.onSetChildren(
391 - this._debugID,
392 - [this._renderedComponent._debugID]
393 - );
390 + if (this._debugID !== 0) {
391 + ReactInstrumentation.debugTool.onSetChildren(
392 + this._debugID,
393 + this._renderedComponent._debugID !== 0 ?
394 + [this._renderedComponent._debugID] :
395 + []
396 + );
397 + }
398 }
399
400 return markup;
@@ -870,10 +874,14 @@ var ReactCompositeComponentMixin = {
874 );
875
876 if (__DEV__) {
873 - ReactInstrumentation.debugTool.onSetChildren(
874 - this._debugID,
875 - [this._renderedComponent._debugID]
876 - );
877 + if (this._debugID !== 0) {
878 + ReactInstrumentation.debugTool.onSetChildren(
879 + this._debugID,
880 + this._renderedComponent._debugID !== 0 ?
881 + [this._renderedComponent._debugID] :
882 + []
883 + );
884 + }
885 }
886
887 this._replaceNodeWithMarkup(oldNativeNode, nextMarkup);
src/renderers/shared/reconciler/ReactReconciler.js
+12 -4
@@ -53,7 +53,9 @@ var ReactReconciler = {
53 transaction.getReactMountReady().enqueue(attachRefs, internalInstance);
54 }
55 if (__DEV__) {
56 - ReactInstrumentation.debugTool.onMountComponent(internalInstance._debugID);
56 + if (internalInstance._debugID !== 0) {
57 + ReactInstrumentation.debugTool.onMountComponent(internalInstance._debugID);
58 + }
59 }
60 return markup;
61 },
@@ -76,7 +78,9 @@ var ReactReconciler = {
78 ReactRef.detachRefs(internalInstance, internalInstance._currentElement);
79 internalInstance.unmountComponent(safely);
80 if (__DEV__) {
79 - ReactInstrumentation.debugTool.onUnmountComponent(internalInstance._debugID);
81 + if (internalInstance._debugID !== 0) {
82 + ReactInstrumentation.debugTool.onUnmountComponent(internalInstance._debugID);
83 + }
84 }
85 },
86
@@ -128,7 +132,9 @@ var ReactReconciler = {
132 }
133
134 if (__DEV__) {
131 - ReactInstrumentation.debugTool.onUpdateComponent(internalInstance._debugID);
135 + if (internalInstance._debugID !== 0) {
136 + ReactInstrumentation.debugTool.onUpdateComponent(internalInstance._debugID);
137 + }
138 }
139 },
140
@@ -145,7 +151,9 @@ var ReactReconciler = {
151 ) {
152 internalInstance.performUpdateIfNecessary(transaction);
153 if (__DEV__) {
148 - ReactInstrumentation.debugTool.onUpdateComponent(internalInstance._debugID);
154 + if (internalInstance._debugID !== 0) {
155 + ReactInstrumentation.debugTool.onUpdateComponent(internalInstance._debugID);
156 + }
157 }
158 },
159
src/renderers/shared/reconciler/instantiateReactComponent.js
+3 -14
@@ -84,12 +84,8 @@ var nextDebugID = 1;
84 function instantiateReactComponent(node) {
85 var instance;
86
87 - var isNative = false;
88 - var isComposite = false;
89 - var isEmpty = false;
90 -
91 - if (node === null || node === false) {
92 - isEmpty = true;
87 + var isEmpty = node === null || node === false;
88 + if (isEmpty) {
89 instance = ReactEmptyComponent.create(instantiateReactComponent);
90 } else if (typeof node === 'object') {
91 var element = node;
@@ -104,16 +100,13 @@ function instantiateReactComponent(node) {
100
101 // Special case string values
102 if (typeof element.type === 'string') {
107 - isNative = true;
103 instance = ReactNativeComponent.createInternalComponent(element);
104 } else if (isInternalComponentType(element.type)) {
110 - isComposite = true;
105 // This is temporarily available for custom components that are not string
106 // representations. I.e. ART. Once those are updated to use the string
107 // representation, we can drop this code path.
108 instance = new element.type(element);
109 } else {
116 - isComposite = true;
110 instance = new ReactCompositeComponentWrapper(element);
111 }
112 } else if (typeof node === 'string' || typeof node === 'number') {
@@ -148,15 +141,11 @@ function instantiateReactComponent(node) {
141 }
142
143 if (__DEV__) {
151 - var debugID = nextDebugID++;
144 + var debugID = isEmpty ? 0 : nextDebugID++;
145 instance._debugID = debugID;
146
147 var displayName = getDisplayName(instance);
148 ReactInstrumentation.debugTool.onSetDisplayName(debugID, displayName);
156 - ReactInstrumentation.debugTool.onSetIsEmpty(debugID, isEmpty);
157 - if (isNative || isComposite) {
158 - ReactInstrumentation.debugTool.onSetChildren(debugID, []);
159 - }
149 var owner = node && node._owner;
150 if (owner) {
151 ReactInstrumentation.debugTool.onSetOwner(debugID, owner._debugID);