mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
updated flow annotations
This commit is contained in:
@@ -14,13 +14,13 @@
|
||||
|
||||
import type { Fiber } from 'ReactFiber';
|
||||
import type { DebugID } from 'ReactInstanceType';
|
||||
import type { ComponentTreeHookDevType } from '../../hooks/ReactComponentTreeHook';
|
||||
import type { ComponentTreeHookDevType } from 'ReactComponentTreeHook';
|
||||
|
||||
const ReactDebugCurrentFrame = {};
|
||||
|
||||
if (__DEV__) {
|
||||
// how do a state that ReactComponentTreeHook is using the ComponentTreeHookDevType type?
|
||||
const ReactComponentTreeHook: ComponentTreeHookDevType = require('ReactComponentTreeHook');
|
||||
const ReactComponentTreeHook: ComponentTreeHookDevType = (require('ReactComponentTreeHook'): any);
|
||||
const {
|
||||
getStackAddendumByID,
|
||||
getStackAddendumByWorkInProgressFiber,
|
||||
|
||||
@@ -71,6 +71,7 @@ export type ComponentTreeHookDevType = {
|
||||
getUpdateCount: (DebugID) => any,
|
||||
getChildIDs: (DebugID) => any,
|
||||
getRegisteredIDs: () => any,
|
||||
getElement: () => any,
|
||||
};
|
||||
|
||||
var ReactComponentTreeHook: ComponentTreeHookType = {
|
||||
|
||||
@@ -22,6 +22,7 @@ var warning = require('fbjs/lib/warning');
|
||||
import type { ReactElement } from 'ReactElementType';
|
||||
import type { DebugID } from 'ReactInstanceType';
|
||||
import type { Operation } from 'ReactHostOperationHistoryHook';
|
||||
import type { ComponentTreeHookDevType } from 'ReactComponentTreeHook';
|
||||
|
||||
type Hook = any;
|
||||
|
||||
@@ -68,7 +69,7 @@ var ReactDebugTool = ((null: any): typeof ReactDebugTool);
|
||||
if (__DEV__) {
|
||||
const hooks = [];
|
||||
const didHookThrowForEvent = {};
|
||||
const ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
||||
const ReactComponentTreeHook: ComponentTreeHookDevType = (require('react/lib/ReactComponentTreeHook'): any);
|
||||
const {
|
||||
purgeUnmountedComponents,
|
||||
getOwnerID,
|
||||
@@ -78,6 +79,7 @@ if (__DEV__) {
|
||||
getUpdateCount,
|
||||
getChildIDs,
|
||||
getRegisteredIDs,
|
||||
getElement,
|
||||
} = ReactComponentTreeHook;
|
||||
|
||||
const callHook = function(event, fn, context, arg1, arg2, arg3, arg4, arg5) {
|
||||
@@ -118,24 +120,22 @@ if (__DEV__) {
|
||||
var lifeCycleTimerHasWarned = false;
|
||||
|
||||
const clearHistory = function() {
|
||||
if (purgeUnmountedComponents) {
|
||||
purgeUnmountedComponents();
|
||||
}
|
||||
purgeUnmountedComponents();
|
||||
ReactHostOperationHistoryHook.clearHistory();
|
||||
};
|
||||
|
||||
const getTreeSnapshot = function(registeredIDs) {
|
||||
return registeredIDs && registeredIDs.reduce((tree, id) => {
|
||||
var ownerID = getOwnerID && getOwnerID(id);
|
||||
var parentID = getParentID && getParentID(id);
|
||||
return registeredIDs.reduce((tree, id) => {
|
||||
var ownerID = getOwnerID(id);
|
||||
var parentID = getParentID(id);
|
||||
tree[id] = {
|
||||
displayName: getDisplayName && getDisplayName(id),
|
||||
text: getText && getText(id),
|
||||
updateCount: getUpdateCount && getUpdateCount(id),
|
||||
childIDs: getChildIDs && getChildIDs(id),
|
||||
displayName: getDisplayName(id),
|
||||
text: getText(id),
|
||||
updateCount: getUpdateCount(id),
|
||||
childIDs: getChildIDs(id),
|
||||
// Text nodes don't have owners but this is close enough.
|
||||
ownerID: ownerID ||
|
||||
parentID && getOwnerID && getOwnerID(parentID) ||
|
||||
parentID && getOwnerID(parentID) ||
|
||||
0,
|
||||
parentID,
|
||||
};
|
||||
@@ -156,16 +156,14 @@ if (__DEV__) {
|
||||
}
|
||||
|
||||
if (previousMeasurements.length || previousOperations.length) {
|
||||
var registeredIDs = getRegisteredIDs && getRegisteredIDs();
|
||||
var registeredIDs = getRegisteredIDs();
|
||||
|
||||
if (registeredIDs) {
|
||||
flushHistory.push({
|
||||
duration: performanceNow() - previousStartTime,
|
||||
measurements: previousMeasurements || [],
|
||||
operations: previousOperations || [],
|
||||
treeSnapshot: getTreeSnapshot(registeredIDs),
|
||||
});
|
||||
}
|
||||
flushHistory.push({
|
||||
duration: performanceNow() - previousStartTime,
|
||||
measurements: previousMeasurements || [],
|
||||
operations: previousOperations || [],
|
||||
treeSnapshot: getTreeSnapshot(registeredIDs),
|
||||
});
|
||||
}
|
||||
|
||||
clearHistory();
|
||||
@@ -268,7 +266,7 @@ if (__DEV__) {
|
||||
if (!isProfiling || !canUsePerformanceMeasure) {
|
||||
return false;
|
||||
}
|
||||
var element = (ReactComponentTreeHook: any).getElement(debugID);
|
||||
var element = getElement(debugID);
|
||||
if (element == null || typeof element !== 'object') {
|
||||
return false;
|
||||
}
|
||||
@@ -295,7 +293,7 @@ if (__DEV__) {
|
||||
}
|
||||
|
||||
var markName = `${debugID}::${markType}`;
|
||||
var displayName = getDisplayName && getDisplayName(debugID) || 'Unknown';
|
||||
var displayName = getDisplayName(debugID) || 'Unknown';
|
||||
|
||||
// Chrome has an issue of dropping markers recorded too fast:
|
||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=640652
|
||||
|
||||
@@ -16,6 +16,7 @@ var ReactOwner = require('ReactOwner');
|
||||
|
||||
import type { ReactInstance } from 'ReactInstanceType';
|
||||
import type { ReactElement } from 'ReactElementType';
|
||||
import type { ComponentTreeHookDevType } from 'ReactComponentTreeHook';
|
||||
|
||||
var ReactRef = {};
|
||||
|
||||
@@ -23,7 +24,7 @@ if (__DEV__) {
|
||||
var ReactCompositeComponentTypes = require('ReactCompositeComponentTypes');
|
||||
var {
|
||||
getStackAddendumByID,
|
||||
} = require('react/lib/ReactComponentTreeHook');
|
||||
}: ComponentTreeHookDevType = (require('react/lib/ReactComponentTreeHook'): any);
|
||||
var warning = require('fbjs/lib/warning');
|
||||
|
||||
var warnedAboutStatelessRefs = {};
|
||||
@@ -55,7 +56,7 @@ function attachRef(ref, component, owner) {
|
||||
'Stateless function components cannot be given refs. ' +
|
||||
'Attempts to access this ref will fail.%s%s',
|
||||
info,
|
||||
getStackAddendumByID && getStackAddendumByID(component._debugID)
|
||||
getStackAddendumByID(component._debugID)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import type { ComponentTreeHookDevType } from 'ReactComponentTreeHook';
|
||||
|
||||
var KeyEscapeUtils = require('KeyEscapeUtils');
|
||||
var traverseAllChildren = require('traverseAllChildren');
|
||||
var warning = require('fbjs/lib/warning');
|
||||
@@ -51,7 +53,7 @@ function flattenSingleChildIntoContext(
|
||||
if (!ReactComponentTreeHook) {
|
||||
ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
||||
}
|
||||
const { getStackAddendumByID } = ReactComponentTreeHook;
|
||||
const { getStackAddendumByID }: ComponentTreeHookDevType = (ReactComponentTreeHook: any);
|
||||
|
||||
if (!keyUnique) {
|
||||
warning(
|
||||
@@ -60,7 +62,7 @@ function flattenSingleChildIntoContext(
|
||||
'`%s`. Child keys must be unique; when two children share a key, only ' +
|
||||
'the first child will be used.%s',
|
||||
KeyEscapeUtils.unescape(name),
|
||||
getStackAddendumByID && getStackAddendumByID(selfDebugID)
|
||||
getStackAddendumByID(selfDebugID)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user