Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6871 - Add not dev warning for ReactPerf & remove dev checking for ReactDebugTool method #6884

Merged
merged 11 commits into from
Jun 6, 2016
4 changes: 1 addition & 3 deletions src/renderers/shared/ReactDebugTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ var ReactDebugTool = {
}
},
getFlushHistory() {
if (__DEV__) {
return flushHistory;
}
return flushHistory;
},
onBeginFlush() {
if (__DEV__) {
Expand Down
65 changes: 65 additions & 0 deletions src/renderers/shared/ReactPerf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,28 @@ function roundFloat(val, base = 2) {
return Math.floor(val * n) / n;
}

function warnInProduction() {
if (typeof console !== 'undefined') {
console.error('ReactPerf is not supported in the production builds of React.' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: let’s start string literal from the next line.

console.error(
  'ga ga ' +
  'o la la'
);

'To collect measurements, please use the development build of React instead.');
}
}

function getFlushHistory() {
if (!__DEV__) {
warnInProduction();
return [];
}

return ReactDebugTool.getFlushHistory();
}

function getExclusive(flushHistory = getFlushHistory()) {
if (!__DEV__) {
warnInProduction();
return [];
}

var aggregatedStats = {};
var affectedIDs = {};

Expand Down Expand Up @@ -74,6 +91,11 @@ function getExclusive(flushHistory = getFlushHistory()) {
}

function getInclusive(flushHistory = getFlushHistory()) {
if (!__DEV__) {
warnInProduction();
return [];
}

var aggregatedStats = {};
var affectedIDs = {};

Expand Down Expand Up @@ -142,6 +164,11 @@ function getInclusive(flushHistory = getFlushHistory()) {
}

function getWasted(flushHistory = getFlushHistory()) {
if (!__DEV__) {
warnInProduction();
return [];
}

var aggregatedStats = {};
var affectedIDs = {};

Expand Down Expand Up @@ -235,6 +262,11 @@ function getWasted(flushHistory = getFlushHistory()) {
}

function getOperations(flushHistory = getFlushHistory()) {
if (!__DEV__) {
warnInProduction();
return [];
}

var stats = [];
flushHistory.forEach((flush, flushIndex) => {
var {operations, treeSnapshot} = flush;
Expand All @@ -258,6 +290,11 @@ function getOperations(flushHistory = getFlushHistory()) {
}

function printExclusive(flushHistory) {
if (!__DEV__) {
warnInProduction();
return '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to return an empty string—we can just return; here.

}

var stats = getExclusive(flushHistory);
var table = stats.map(item => {
var {key, instanceCount, totalDuration} = item;
Expand All @@ -279,6 +316,11 @@ function printExclusive(flushHistory) {
}

function printInclusive(flushHistory) {
if (!__DEV__) {
warnInProduction();
return '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here and in any print* method below.

}

var stats = getInclusive(flushHistory);
var table = stats.map(item => {
var {key, instanceCount, inclusiveRenderDuration, renderCount} = item;
Expand All @@ -293,6 +335,11 @@ function printInclusive(flushHistory) {
}

function printWasted(flushHistory) {
if (!__DEV__) {
warnInProduction();
return '';
}

var stats = getWasted(flushHistory);
var table = stats.map(item => {
var {key, instanceCount, inclusiveRenderDuration, renderCount} = item;
Expand All @@ -307,6 +354,11 @@ function printWasted(flushHistory) {
}

function printOperations(flushHistory) {
if (!__DEV__) {
warnInProduction();
return '';
}

var stats = getOperations(flushHistory);
var table = stats.map(stat => ({
'Owner > Node': stat.key,
Expand Down Expand Up @@ -344,14 +396,27 @@ function getMeasurementsSummaryMap(measurements) {
}

function start() {
if (!__DEV__) {
warnInProduction();
return;
}
ReactDebugTool.beginProfiling();
}

function stop() {
if (!__DEV__) {
warnInProduction();
return;
}

ReactDebugTool.endProfiling();
}

function isRunning() {
if (!__DEV__) {
warnInProduction();
return false;
}
return ReactDebugTool.isProfiling();
}

Expand Down