Gate more code with if (__DEV__) { }

Reviewed By: amnn

Differential Revision: D5621165

fbshipit-source-id: ee8b3df523858323a3ce4484ab56fcae0da3d633
This commit is contained in:
Alexey Lang 2017-08-14 07:10:27 -07:00 committed by Facebook Github Bot
parent 419652d4e9
commit f11f00197d

View File

@ -39,9 +39,8 @@ let _useFiber = false;
// Implements a subset of User Timing API necessary for React measurements.
// https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API
const REACT_MARKER = '\u269B';
const userTimingPolyfill = {
const userTimingPolyfill = __DEV__ ? {
mark(markName: string) {
if (__DEV__) {
if (_enabled) {
_markStackIndex++;
_markStack[_markStackIndex] = markName;
@ -58,10 +57,8 @@ const userTimingPolyfill = {
}
Systrace.beginEvent(systraceLabel);
}
}
},
measure(measureName: string, startMark: ?string, endMark: ?string) {
if (__DEV__) {
if (_enabled) {
invariant(
typeof measureName === 'string' &&
@ -82,10 +79,8 @@ const userTimingPolyfill = {
// let us edit labels post factum.
Systrace.endEvent();
}
}
},
clearMarks(markName: string) {
if (__DEV__) {
if (_enabled) {
if (_markStackIndex === -1) {
return;
@ -93,6 +88,7 @@ const userTimingPolyfill = {
if (markName === _markStack[_markStackIndex]) {
// React uses this for "cancelling" started measurements.
// Systrace doesn't support deleting measurements, so we just stop them.
if (userTimingPolyfill != null) {
userTimingPolyfill.measure(markName, markName);
}
}
@ -102,10 +98,10 @@ const userTimingPolyfill = {
// React calls this to avoid memory leaks in browsers, but we don't keep
// measurements anyway.
},
};
} : null;
// A hook to get React Stack markers in Systrace.
const reactDebugToolHook = {
const reactDebugToolHook = __DEV__ ? {
onBeforeMountComponent(debugID) {
const ReactComponentTreeHook = require('ReactGlobalSharedState').ReactComponentTreeHook;
const displayName = ReactComponentTreeHook.getDisplayName(debugID);
@ -138,17 +134,19 @@ const reactDebugToolHook = {
onEndLifeCycleTimer(debugID, timerType) {
Systrace.endEvent();
},
};
} : null;
const Systrace = {
installReactHook(useFiber: boolean) {
if (_enabled) {
if (__DEV__) {
if (useFiber) {
global.performance = userTimingPolyfill;
} else {
require('ReactDebugTool').addHook(reactDebugToolHook);
}
}
}
_useFiber = useFiber;
_canInstallReactHook = true;
},