From 51d37c64c3736d9356469642e5480481128cf6c0 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Thu, 17 Mar 2016 18:46:52 +0000 Subject: [PATCH] Make ReactPerf measurements opaque We intend to change the measurement format significantly in #6046. In order to introduce the new ReactPerf during 15.x release cycle, we are making the measurement structure opaque-ish in 15.0. --- src/test/ReactDefaultPerf.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/test/ReactDefaultPerf.js b/src/test/ReactDefaultPerf.js index 782f0e30435c8..b1a2e56937034 100644 --- a/src/test/ReactDefaultPerf.js +++ b/src/test/ReactDefaultPerf.js @@ -51,6 +51,17 @@ function getID(inst) { } } +// This implementation of ReactPerf is going away some time mid 15.x. +// While we plan to keep most of the API, the actual format of measurements +// will change dramatically. To signal this, we wrap them into an opaque-ish +// object to discourage reaching into it until the API stabilizes. +function wrapLegacyMeasurements(measurements) { + return { __unstable_this_format_will_change: measurements }; +} +function unwrapLegacyMeasurements(measurements) { + return measurements && measurements.__unstable_this_format_will_change || measurements; +} + var ReactDefaultPerf = { _allMeasurements: [], // last item in the list is the current one _mountStack: [0], @@ -71,11 +82,11 @@ var ReactDefaultPerf = { }, getLastMeasurements: function() { - return ReactDefaultPerf._allMeasurements; + return wrapLegacyMeasurements(ReactDefaultPerf._allMeasurements); }, printExclusive: function(measurements) { - measurements = measurements || ReactDefaultPerf._allMeasurements; + measurements = unwrapLegacyMeasurements(measurements || ReactDefaultPerf._allMeasurements); var summary = ReactDefaultPerfAnalysis.getExclusiveSummary(measurements); console.table(summary.map(function(item) { return { @@ -93,7 +104,7 @@ var ReactDefaultPerf = { }, printInclusive: function(measurements) { - measurements = measurements || ReactDefaultPerf._allMeasurements; + measurements = unwrapLegacyMeasurements(measurements || ReactDefaultPerf._allMeasurements); var summary = ReactDefaultPerfAnalysis.getInclusiveSummary(measurements); console.table(summary.map(function(item) { return { @@ -109,6 +120,7 @@ var ReactDefaultPerf = { }, getMeasurementsSummaryMap: function(measurements) { + measurements = unwrapLegacyMeasurements(measurements); var summary = ReactDefaultPerfAnalysis.getInclusiveSummary( measurements, true @@ -123,7 +135,7 @@ var ReactDefaultPerf = { }, printWasted: function(measurements) { - measurements = measurements || ReactDefaultPerf._allMeasurements; + measurements = unwrapLegacyMeasurements(measurements || ReactDefaultPerf._allMeasurements); console.table(ReactDefaultPerf.getMeasurementsSummaryMap(measurements)); console.log( 'Total time:', @@ -132,7 +144,7 @@ var ReactDefaultPerf = { }, printDOM: function(measurements) { - measurements = measurements || ReactDefaultPerf._allMeasurements; + measurements = unwrapLegacyMeasurements(measurements || ReactDefaultPerf._allMeasurements); var summary = ReactDefaultPerfAnalysis.getDOMSummary(measurements); console.table(summary.map(function(item) { var result = {};