2016-12-16 00:36:58 +08:00
|
|
|
/**
|
|
|
|
|
* 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 ReactDebugCurrentFiber
|
|
|
|
|
* @flow
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
import type { Fiber } from 'ReactFiber';
|
|
|
|
|
|
|
|
|
|
if (__DEV__) {
|
|
|
|
|
var getComponentName = require('getComponentName');
|
|
|
|
|
var { getStackAddendumByWorkInProgressFiber } = require('ReactComponentTreeHook');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getCurrentFiberOwnerName() : string | null {
|
|
|
|
|
if (__DEV__) {
|
|
|
|
|
const fiber = ReactDebugCurrentFiber.current;
|
2017-02-11 09:30:09 +08:00
|
|
|
if (fiber === null) {
|
2016-12-16 00:36:58 +08:00
|
|
|
return null;
|
|
|
|
|
}
|
2017-01-10 07:09:18 +08:00
|
|
|
if (fiber._debugOwner != null) {
|
|
|
|
|
return getComponentName(fiber._debugOwner);
|
2016-12-16 00:36:58 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getCurrentFiberStackAddendum() : string | null {
|
|
|
|
|
if (__DEV__) {
|
|
|
|
|
const fiber = ReactDebugCurrentFiber.current;
|
2017-02-11 09:30:09 +08:00
|
|
|
if (fiber === null) {
|
2016-12-16 00:36:58 +08:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
// Safe because if current fiber exists, we are reconciling,
|
|
|
|
|
// and it is guaranteed to be the work-in-progress version.
|
|
|
|
|
return getStackAddendumByWorkInProgressFiber(fiber);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ReactDebugCurrentFiber = {
|
|
|
|
|
current: (null : Fiber | null),
|
|
|
|
|
getCurrentFiberOwnerName,
|
|
|
|
|
getCurrentFiberStackAddendum,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = ReactDebugCurrentFiber;
|