-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
gaearon
merged 11 commits into
facebook:master
from
sashashakun:react-perf-warnings-changes
Jun 6, 2016
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
64412a0
add not dev warning for ReactPerf & remove dev checking for ReactDebu…
sashashakun 878a99f
move from warn to console.error & add explicitly returns
sashashakun 2840d5e
fix linter errors
sashashakun 33ae3f6
more fixes after review
sashashakun 25b0810
roll back alreadyWarned variable and its changes
sashashakun ec4f40c
more fixes after review
sashashakun d868334
move from one if to two
sashashakun a8b46fb
a little fix after review
sashashakun 499d822
Merge branch 'master' into react-perf-warnings-changes
sashashakun 497d94b
add tests and fix bug in solution
sashashakun 2116205
after review fixes
sashashakun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.' + | ||
'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 = {}; | ||
|
||
|
@@ -74,6 +91,11 @@ function getExclusive(flushHistory = getFlushHistory()) { | |
} | ||
|
||
function getInclusive(flushHistory = getFlushHistory()) { | ||
if (!__DEV__) { | ||
warnInProduction(); | ||
return []; | ||
} | ||
|
||
var aggregatedStats = {}; | ||
var affectedIDs = {}; | ||
|
||
|
@@ -142,6 +164,11 @@ function getInclusive(flushHistory = getFlushHistory()) { | |
} | ||
|
||
function getWasted(flushHistory = getFlushHistory()) { | ||
if (!__DEV__) { | ||
warnInProduction(); | ||
return []; | ||
} | ||
|
||
var aggregatedStats = {}; | ||
var affectedIDs = {}; | ||
|
||
|
@@ -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; | ||
|
@@ -258,6 +290,11 @@ function getOperations(flushHistory = getFlushHistory()) { | |
} | ||
|
||
function printExclusive(flushHistory) { | ||
if (!__DEV__) { | ||
warnInProduction(); | ||
return ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to return an empty string—we can just |
||
} | ||
|
||
var stats = getExclusive(flushHistory); | ||
var table = stats.map(item => { | ||
var {key, instanceCount, totalDuration} = item; | ||
|
@@ -279,6 +316,11 @@ function printExclusive(flushHistory) { | |
} | ||
|
||
function printInclusive(flushHistory) { | ||
if (!__DEV__) { | ||
warnInProduction(); | ||
return ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here and in any |
||
} | ||
|
||
var stats = getInclusive(flushHistory); | ||
var table = stats.map(item => { | ||
var {key, instanceCount, inclusiveRenderDuration, renderCount} = item; | ||
|
@@ -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; | ||
|
@@ -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, | ||
|
@@ -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(); | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.