@samitouri / QOS-React / commits / 393cdbc745

Consolidate ReactCurrentFiber and ReactDebugLifeCycle

Andrew Clark committed Feb 23, 2017 at 13:33 UTC 393cdbc745ffca800f04b2ee2e7e78a11cbb8a1e
6 files changed +17 -47
src/renderers/shared/fiber/ReactDebugCurrentFiber.js
+4
@@ -14,6 +14,8 @@
14
15 import type { Fiber } from 'ReactFiber';
16
17 +type LifeCyclePhase = 'render' | 'getChildContext';
18 +
19 if (__DEV__) {
20 var getComponentName = require('getComponentName');
21 var { getStackAddendumByWorkInProgressFiber } = require('ReactComponentTreeHook');
@@ -47,6 +49,8 @@ function getCurrentFiberStackAddendum() : string | null {
49
50 var ReactDebugCurrentFiber = {
51 current: (null : Fiber | null),
52 + phase: (null : LifeCyclePhase | null),
53 +
54 getCurrentFiberOwnerName,
55 getCurrentFiberStackAddendum,
56 };
src/renderers/shared/fiber/ReactFiberBeginWork.js
+4 -9
@@ -66,7 +66,6 @@ var invariant = require('invariant');
66
67 if (__DEV__) {
68 var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber');
69 - var ReactDebugLifeCycle = require('ReactDebugLifeCycle');
69 var warning = require('warning');
70 var warnedAboutStatelessRefs = {};
71 }
@@ -231,11 +230,9 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
230
231 if (__DEV__) {
232 ReactCurrentOwner.current = workInProgress;
234 - ReactDebugLifeCycle.current = workInProgress;
235 - ReactDebugLifeCycle.phase = 'render';
233 + ReactDebugCurrentFiber.phase = 'render';
234 nextChildren = fn(nextProps, context);
237 - ReactDebugLifeCycle.current = null;
238 - ReactDebugLifeCycle.phase = null;
235 + ReactDebugCurrentFiber.phase = null;
236 } else {
237 nextChildren = fn(nextProps, context);
238 }
@@ -286,11 +283,9 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
283 ReactCurrentOwner.current = workInProgress;
284 let nextChildren;
285 if (__DEV__) {
289 - ReactDebugLifeCycle.current = workInProgress;
290 - ReactDebugLifeCycle.phase = 'render';
286 + ReactDebugCurrentFiber.phase = 'render';
287 nextChildren = instance.render();
292 - ReactDebugLifeCycle.current = null;
293 - ReactDebugLifeCycle.phase = null;
288 + ReactDebugCurrentFiber.phase = null;
289 } else {
290 nextChildren = instance.render();
291 }
src/renderers/shared/fiber/ReactFiberContext.js
+3 -5
@@ -35,7 +35,7 @@ const {
35 if (__DEV__) {
36 var checkReactTypeSpec = require('checkReactTypeSpec');
37 var ReactDebugCurrentFrame = require('ReactDebugCurrentFrame');
38 - var ReactDebugLifeCycle = require('ReactDebugLifeCycle');
38 + var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber');
39 var warnedAboutMissingGetChildContext = {};
40 }
41
@@ -171,11 +171,9 @@ function processChildContext(fiber : Fiber, parentContext : Object, isReconcilin
171
172 let childContext;
173 if (__DEV__) {
174 - ReactDebugLifeCycle.current = fiber;
175 - ReactDebugLifeCycle.phase = 'getChildContext';
174 + ReactDebugCurrentFiber.phase = 'getChildContext';
175 childContext = instance.getChildContext();
177 - ReactDebugLifeCycle.current = null;
178 - ReactDebugLifeCycle.phase = null;
176 + ReactDebugCurrentFiber.phase = null;
177 } else {
178 childContext = instance.getChildContext();
179 }
src/renderers/shared/fiber/ReactFiberReconciler.js
+4 -5
@@ -32,8 +32,7 @@ var ReactFiberScheduler = require('ReactFiberScheduler');
32 if (__DEV__) {
33 var warning = require('warning');
34 var ReactFiberInstrumentation = require('ReactFiberInstrumentation');
35 - var warning = require('warning');
36 - var ReactDebugLifeCycle = require('ReactDebugLifeCycle');
35 + var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber');
36 var { getComponentName } = require('ReactFiberTreeReflection');
37 }
38
@@ -148,14 +147,14 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
147
148 function scheduleTopLevelUpdate(current : Fiber, element : ReactNodeList, callback : ?Function) {
149 if (__DEV__) {
151 - if (ReactDebugLifeCycle.current !== null) {
150 + if (ReactDebugCurrentFiber.current !== null) {
151 warning(
153 - ReactDebugLifeCycle.phase !== 'render',
152 + ReactDebugCurrentFiber.phase !== 'render',
153 'Render methods should be a pure function of props and state; ' +
154 'triggering nested component updates from render is not allowed. ' +
155 'If necessary, trigger nested updates in componentDidUpdate.\n\n' +
156 'Check the render method of %s.',
158 - getComponentName(ReactDebugLifeCycle.current)
157 + getComponentName(ReactDebugCurrentFiber.current)
158 );
159 }
160 }
src/renderers/shared/fiber/ReactFiberScheduler.js
+2 -4
@@ -90,7 +90,6 @@ if (__DEV__) {
90 var warning = require('warning');
91 var ReactFiberInstrumentation = require('ReactFiberInstrumentation');
92 var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber');
93 - var ReactDebugLifeCycle = require('ReactDebugLifeCycle');
93
94 var warnAboutUpdateOnUnmounted = function(instance : ReactClass<any>) {
95 const ctor = instance.constructor;
@@ -105,7 +104,7 @@ if (__DEV__) {
104 };
105
106 var warnAboutInvalidUpdates = function(instance : ReactClass<any>) {
108 - switch (ReactDebugLifeCycle.phase) {
107 + switch (ReactDebugCurrentFiber.phase) {
108 case 'getChildContext':
109 warning(
110 false,
@@ -880,8 +879,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
879 ReactCurrentOwner.current = null;
880 if (__DEV__) {
881 ReactDebugCurrentFiber.current = null;
883 - ReactDebugLifeCycle.current = null;
884 - ReactDebugLifeCycle.phase = null;
882 + ReactDebugCurrentFiber.phase = null;
883 }
884 // It is no longer valid because this unit of work failed.
885 nextUnitOfWork = null;
src/renderers/shared/fiber/isomorphic/ReactDebugLifeCycle.js deleted
-24
@@ -1,24 +0,0 @@
1 -/**
2 - * Copyright 2013-present, Facebook, Inc.
3 - * All rights reserved.
4 - *
5 - * This source code is licensed under the BSD-style license found in the
6 - * LICENSE file in the root directory of this source tree. An additional grant
7 - * of patent rights can be found in the PATENTS file in the same directory.
8 - *
9 - * @providesModule ReactDebugLifeCycle
10 - * @flow
11 - */
12 -
13 -'use strict';
14 -
15 -import type { Fiber } from 'ReactFiber';
16 -
17 -type LifeCyclePhase = 'render' | 'getChildContext';
18 -
19 -const ReactDebugLifeCycle = {
20 - current: (null : Fiber | null),
21 - phase: (null : LifeCyclePhase | null),
22 -};
23 -
24 -module.exports = ReactDebugLifeCycle;