mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Consolidate ReactCurrentFiber and ReactDebugLifeCycle
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
|
||||
import type { Fiber } from 'ReactFiber';
|
||||
|
||||
type LifeCyclePhase = 'render' | 'getChildContext';
|
||||
|
||||
if (__DEV__) {
|
||||
var getComponentName = require('getComponentName');
|
||||
var { getStackAddendumByWorkInProgressFiber } = require('ReactComponentTreeHook');
|
||||
@@ -47,6 +49,8 @@ function getCurrentFiberStackAddendum() : string | null {
|
||||
|
||||
var ReactDebugCurrentFiber = {
|
||||
current: (null : Fiber | null),
|
||||
phase: (null : LifeCyclePhase | null),
|
||||
|
||||
getCurrentFiberOwnerName,
|
||||
getCurrentFiberStackAddendum,
|
||||
};
|
||||
|
||||
@@ -66,7 +66,6 @@ var invariant = require('invariant');
|
||||
|
||||
if (__DEV__) {
|
||||
var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber');
|
||||
var ReactDebugLifeCycle = require('ReactDebugLifeCycle');
|
||||
var warning = require('warning');
|
||||
var warnedAboutStatelessRefs = {};
|
||||
}
|
||||
@@ -231,11 +230,9 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
|
||||
|
||||
if (__DEV__) {
|
||||
ReactCurrentOwner.current = workInProgress;
|
||||
ReactDebugLifeCycle.current = workInProgress;
|
||||
ReactDebugLifeCycle.phase = 'render';
|
||||
ReactDebugCurrentFiber.phase = 'render';
|
||||
nextChildren = fn(nextProps, context);
|
||||
ReactDebugLifeCycle.current = null;
|
||||
ReactDebugLifeCycle.phase = null;
|
||||
ReactDebugCurrentFiber.phase = null;
|
||||
} else {
|
||||
nextChildren = fn(nextProps, context);
|
||||
}
|
||||
@@ -286,11 +283,9 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
|
||||
ReactCurrentOwner.current = workInProgress;
|
||||
let nextChildren;
|
||||
if (__DEV__) {
|
||||
ReactDebugLifeCycle.current = workInProgress;
|
||||
ReactDebugLifeCycle.phase = 'render';
|
||||
ReactDebugCurrentFiber.phase = 'render';
|
||||
nextChildren = instance.render();
|
||||
ReactDebugLifeCycle.current = null;
|
||||
ReactDebugLifeCycle.phase = null;
|
||||
ReactDebugCurrentFiber.phase = null;
|
||||
} else {
|
||||
nextChildren = instance.render();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ const {
|
||||
if (__DEV__) {
|
||||
var checkReactTypeSpec = require('checkReactTypeSpec');
|
||||
var ReactDebugCurrentFrame = require('ReactDebugCurrentFrame');
|
||||
var ReactDebugLifeCycle = require('ReactDebugLifeCycle');
|
||||
var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber');
|
||||
var warnedAboutMissingGetChildContext = {};
|
||||
}
|
||||
|
||||
@@ -171,11 +171,9 @@ function processChildContext(fiber : Fiber, parentContext : Object, isReconcilin
|
||||
|
||||
let childContext;
|
||||
if (__DEV__) {
|
||||
ReactDebugLifeCycle.current = fiber;
|
||||
ReactDebugLifeCycle.phase = 'getChildContext';
|
||||
ReactDebugCurrentFiber.phase = 'getChildContext';
|
||||
childContext = instance.getChildContext();
|
||||
ReactDebugLifeCycle.current = null;
|
||||
ReactDebugLifeCycle.phase = null;
|
||||
ReactDebugCurrentFiber.phase = null;
|
||||
} else {
|
||||
childContext = instance.getChildContext();
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ var ReactFiberScheduler = require('ReactFiberScheduler');
|
||||
if (__DEV__) {
|
||||
var warning = require('warning');
|
||||
var ReactFiberInstrumentation = require('ReactFiberInstrumentation');
|
||||
var warning = require('warning');
|
||||
var ReactDebugLifeCycle = require('ReactDebugLifeCycle');
|
||||
var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber');
|
||||
var { getComponentName } = require('ReactFiberTreeReflection');
|
||||
}
|
||||
|
||||
@@ -148,14 +147,14 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
|
||||
|
||||
function scheduleTopLevelUpdate(current : Fiber, element : ReactNodeList, callback : ?Function) {
|
||||
if (__DEV__) {
|
||||
if (ReactDebugLifeCycle.current !== null) {
|
||||
if (ReactDebugCurrentFiber.current !== null) {
|
||||
warning(
|
||||
ReactDebugLifeCycle.phase !== 'render',
|
||||
ReactDebugCurrentFiber.phase !== 'render',
|
||||
'Render methods should be a pure function of props and state; ' +
|
||||
'triggering nested component updates from render is not allowed. ' +
|
||||
'If necessary, trigger nested updates in componentDidUpdate.\n\n' +
|
||||
'Check the render method of %s.',
|
||||
getComponentName(ReactDebugLifeCycle.current)
|
||||
getComponentName(ReactDebugCurrentFiber.current)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,6 @@ if (__DEV__) {
|
||||
var warning = require('warning');
|
||||
var ReactFiberInstrumentation = require('ReactFiberInstrumentation');
|
||||
var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber');
|
||||
var ReactDebugLifeCycle = require('ReactDebugLifeCycle');
|
||||
|
||||
var warnAboutUpdateOnUnmounted = function(instance : ReactClass<any>) {
|
||||
const ctor = instance.constructor;
|
||||
@@ -105,7 +104,7 @@ if (__DEV__) {
|
||||
};
|
||||
|
||||
var warnAboutInvalidUpdates = function(instance : ReactClass<any>) {
|
||||
switch (ReactDebugLifeCycle.phase) {
|
||||
switch (ReactDebugCurrentFiber.phase) {
|
||||
case 'getChildContext':
|
||||
warning(
|
||||
false,
|
||||
@@ -880,8 +879,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
|
||||
ReactCurrentOwner.current = null;
|
||||
if (__DEV__) {
|
||||
ReactDebugCurrentFiber.current = null;
|
||||
ReactDebugLifeCycle.current = null;
|
||||
ReactDebugLifeCycle.phase = null;
|
||||
ReactDebugCurrentFiber.phase = null;
|
||||
}
|
||||
// It is no longer valid because this unit of work failed.
|
||||
nextUnitOfWork = null;
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/**
|
||||
* Copyright 2013-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule ReactDebugLifeCycle
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type { Fiber } from 'ReactFiber';
|
||||
|
||||
type LifeCyclePhase = 'render' | 'getChildContext';
|
||||
|
||||
const ReactDebugLifeCycle = {
|
||||
current: (null : Fiber | null),
|
||||
phase: (null : LifeCyclePhase | null),
|
||||
};
|
||||
|
||||
module.exports = ReactDebugLifeCycle;
|
||||
Reference in New Issue
Block a user