@samitouri / QOS-React / commits / 1f7cbb63e8

updated flow annotations

Dominic Gannaway committed Mar 2, 2017 at 22:06 UTC 1f7cbb63e81fcdf9c81aee86478703f603575a8f
5 files changed +32 -30
src/isomorphic/classic/element/ReactDebugCurrentFrame.js
+2 -2
@@ -14,13 +14,13 @@
14
15 import type { Fiber } from 'ReactFiber';
16 import type { DebugID } from 'ReactInstanceType';
17 -import type { ComponentTreeHookDevType } from '../../hooks/ReactComponentTreeHook';
17 +import type { ComponentTreeHookDevType } from 'ReactComponentTreeHook';
18
19 const ReactDebugCurrentFrame = {};
20
21 if (__DEV__) {
22 // how do a state that ReactComponentTreeHook is using the ComponentTreeHookDevType type?
23 - const ReactComponentTreeHook: ComponentTreeHookDevType = require('ReactComponentTreeHook');
23 + const ReactComponentTreeHook: ComponentTreeHookDevType = (require('ReactComponentTreeHook'): any);
24 const {
25 getStackAddendumByID,
26 getStackAddendumByWorkInProgressFiber,
src/isomorphic/hooks/ReactComponentTreeHook.js
+1
@@ -71,6 +71,7 @@ export type ComponentTreeHookDevType = {
71 getUpdateCount: (DebugID) => any,
72 getChildIDs: (DebugID) => any,
73 getRegisteredIDs: () => any,
74 + getElement: () => any,
75 };
76
77 var ReactComponentTreeHook: ComponentTreeHookType = {
src/renderers/shared/ReactDebugTool.js
+22 -24
@@ -22,6 +22,7 @@ var warning = require('fbjs/lib/warning');
22 import type { ReactElement } from 'ReactElementType';
23 import type { DebugID } from 'ReactInstanceType';
24 import type { Operation } from 'ReactHostOperationHistoryHook';
25 +import type { ComponentTreeHookDevType } from 'ReactComponentTreeHook';
26
27 type Hook = any;
28
@@ -68,7 +69,7 @@ var ReactDebugTool = ((null: any): typeof ReactDebugTool);
69 if (__DEV__) {
70 const hooks = [];
71 const didHookThrowForEvent = {};
71 - const ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
72 + const ReactComponentTreeHook: ComponentTreeHookDevType = (require('react/lib/ReactComponentTreeHook'): any);
73 const {
74 purgeUnmountedComponents,
75 getOwnerID,
@@ -78,6 +79,7 @@ if (__DEV__) {
79 getUpdateCount,
80 getChildIDs,
81 getRegisteredIDs,
82 + getElement,
83 } = ReactComponentTreeHook;
84
85 const callHook = function(event, fn, context, arg1, arg2, arg3, arg4, arg5) {
@@ -118,24 +120,22 @@ if (__DEV__) {
120 var lifeCycleTimerHasWarned = false;
121
122 const clearHistory = function() {
121 - if (purgeUnmountedComponents) {
122 - purgeUnmountedComponents();
123 - }
123 + purgeUnmountedComponents();
124 ReactHostOperationHistoryHook.clearHistory();
125 };
126
127 const getTreeSnapshot = function(registeredIDs) {
128 - return registeredIDs && registeredIDs.reduce((tree, id) => {
129 - var ownerID = getOwnerID && getOwnerID(id);
130 - var parentID = getParentID && getParentID(id);
128 + return registeredIDs.reduce((tree, id) => {
129 + var ownerID = getOwnerID(id);
130 + var parentID = getParentID(id);
131 tree[id] = {
132 - displayName: getDisplayName && getDisplayName(id),
133 - text: getText && getText(id),
134 - updateCount: getUpdateCount && getUpdateCount(id),
135 - childIDs: getChildIDs && getChildIDs(id),
132 + displayName: getDisplayName(id),
133 + text: getText(id),
134 + updateCount: getUpdateCount(id),
135 + childIDs: getChildIDs(id),
136 // Text nodes don't have owners but this is close enough.
137 ownerID: ownerID ||
138 - parentID && getOwnerID && getOwnerID(parentID) ||
138 + parentID && getOwnerID(parentID) ||
139 0,
140 parentID,
141 };
@@ -156,16 +156,14 @@ if (__DEV__) {
156 }
157
158 if (previousMeasurements.length || previousOperations.length) {
159 - var registeredIDs = getRegisteredIDs && getRegisteredIDs();
160 -
161 - if (registeredIDs) {
162 - flushHistory.push({
163 - duration: performanceNow() - previousStartTime,
164 - measurements: previousMeasurements || [],
165 - operations: previousOperations || [],
166 - treeSnapshot: getTreeSnapshot(registeredIDs),
167 - });
168 - }
159 + var registeredIDs = getRegisteredIDs();
160 +
161 + flushHistory.push({
162 + duration: performanceNow() - previousStartTime,
163 + measurements: previousMeasurements || [],
164 + operations: previousOperations || [],
165 + treeSnapshot: getTreeSnapshot(registeredIDs),
166 + });
167 }
168
169 clearHistory();
@@ -268,7 +266,7 @@ if (__DEV__) {
266 if (!isProfiling || !canUsePerformanceMeasure) {
267 return false;
268 }
271 - var element = (ReactComponentTreeHook: any).getElement(debugID);
269 + var element = getElement(debugID);
270 if (element == null || typeof element !== 'object') {
271 return false;
272 }
@@ -295,7 +293,7 @@ if (__DEV__) {
293 }
294
295 var markName = `${debugID}::${markType}`;
298 - var displayName = getDisplayName && getDisplayName(debugID) || 'Unknown';
296 + var displayName = getDisplayName(debugID) || 'Unknown';
297
298 // Chrome has an issue of dropping markers recorded too fast:
299 // https://bugs.chromium.org/p/chromium/issues/detail?id=640652
src/renderers/shared/stack/reconciler/ReactRef.js
+3 -2
@@ -16,6 +16,7 @@ var ReactOwner = require('ReactOwner');
16
17 import type { ReactInstance } from 'ReactInstanceType';
18 import type { ReactElement } from 'ReactElementType';
19 +import type { ComponentTreeHookDevType } from 'ReactComponentTreeHook';
20
21 var ReactRef = {};
22
@@ -23,7 +24,7 @@ if (__DEV__) {
24 var ReactCompositeComponentTypes = require('ReactCompositeComponentTypes');
25 var {
26 getStackAddendumByID,
26 - } = require('react/lib/ReactComponentTreeHook');
27 + }: ComponentTreeHookDevType = (require('react/lib/ReactComponentTreeHook'): any);
28 var warning = require('fbjs/lib/warning');
29
30 var warnedAboutStatelessRefs = {};
@@ -55,7 +56,7 @@ function attachRef(ref, component, owner) {
56 'Stateless function components cannot be given refs. ' +
57 'Attempts to access this ref will fail.%s%s',
58 info,
58 - getStackAddendumByID && getStackAddendumByID(component._debugID)
59 + getStackAddendumByID(component._debugID)
60 );
61 }
62 }
src/shared/utils/flattenChildren.js
+4 -2
@@ -12,6 +12,8 @@
12
13 'use strict';
14
15 +import type { ComponentTreeHookDevType } from 'ReactComponentTreeHook';
16 +
17 var KeyEscapeUtils = require('KeyEscapeUtils');
18 var traverseAllChildren = require('traverseAllChildren');
19 var warning = require('fbjs/lib/warning');
@@ -51,7 +53,7 @@ function flattenSingleChildIntoContext(
53 if (!ReactComponentTreeHook) {
54 ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
55 }
54 - const { getStackAddendumByID } = ReactComponentTreeHook;
56 + const { getStackAddendumByID }: ComponentTreeHookDevType = (ReactComponentTreeHook: any);
57
58 if (!keyUnique) {
59 warning(
@@ -60,7 +62,7 @@ function flattenSingleChildIntoContext(
62 '`%s`. Child keys must be unique; when two children share a key, only ' +
63 'the first child will be used.%s',
64 KeyEscapeUtils.unescape(name),
63 - getStackAddendumByID && getStackAddendumByID(selfDebugID)
65 + getStackAddendumByID(selfDebugID)
66 );
67 }
68 }