React 所有者堆栈重置
一、作用
二、重置所有者堆栈限制
export function resetOwnerStackLimit() {
if (__DEV__) {
const now = getCurrentTime();
const timeSinceLastReset = now - lastResetTime;
if (timeSinceLastReset > 1000) {
ReactSharedInternals.recentlyCreatedOwnerStacks = 0;
lastResetTime = now;
}
} else {
// These errors should never make it into a build so we don't need to encode them in codes.json
// 这些错误永远不应该出现在构建中,所以我们不需要在 codes.json 中对它们进行编码
throw new Error(
'resetOwnerStackLimit should never be called in production mode. This is a bug in React.',
);
}
}
三、常量
1. 现在有性能
const hasPerformanceNow =
typeof performance === 'object' && typeof performance.now === 'function';
if (hasPerformanceNow) {
const localPerformance = performance;
getCurrentTime = () => localPerformance.now();
} else {
const localDate = Date;
getCurrentTime = () => localDate.now();
}
四、变量
1. 上次重置时间
let lastResetTime = 0;
五、工具
1. 获取当前时间
let getCurrentTime: () => number | DOMHighResTimeStamp;