diff --git a/src/renderers/dom/shared/ReactDOMDebugTool.js b/src/renderers/dom/shared/ReactDOMDebugTool.js index a1c1124b5b30c..aae63af9164c9 100644 --- a/src/renderers/dom/shared/ReactDOMDebugTool.js +++ b/src/renderers/dom/shared/ReactDOMDebugTool.js @@ -11,6 +11,8 @@ 'use strict'; +var ReactDOMNullInputValuePropDevtool = require('ReactDOMNullInputValuePropDevtool'); +var ReactDOMUnknownPropertyDevtool = require('ReactDOMUnknownPropertyDevtool'); var ReactDebugTool = require('ReactDebugTool'); var warning = require('warning'); @@ -19,23 +21,21 @@ var eventHandlers = []; var handlerDoesThrowForEvent = {}; function emitEvent(handlerFunctionName, arg1, arg2, arg3, arg4, arg5) { - if (__DEV__) { - eventHandlers.forEach(function(handler) { - try { - if (handler[handlerFunctionName]) { - handler[handlerFunctionName](arg1, arg2, arg3, arg4, arg5); - } - } catch (e) { - warning( - handlerDoesThrowForEvent[handlerFunctionName], - 'exception thrown by devtool while handling %s: %s', - handlerFunctionName, - e + '\n' + e.stack - ); - handlerDoesThrowForEvent[handlerFunctionName] = true; + eventHandlers.forEach(function(handler) { + try { + if (handler[handlerFunctionName]) { + handler[handlerFunctionName](arg1, arg2, arg3, arg4, arg5); } - }); - } + } catch (e) { + warning( + handlerDoesThrowForEvent[handlerFunctionName], + 'exception thrown by devtool while handling %s: %s', + handlerFunctionName, + e + '\n' + e.stack + ); + handlerDoesThrowForEvent[handlerFunctionName] = true; + } + }); } var ReactDOMDebugTool = { @@ -66,11 +66,7 @@ var ReactDOMDebugTool = { }, }; -if (__DEV__) { - var ReactDOMNullInputValuePropDevtool = require('ReactDOMNullInputValuePropDevtool'); - var ReactDOMUnknownPropertyDevtool = require('ReactDOMUnknownPropertyDevtool'); - ReactDOMDebugTool.addDevtool(ReactDOMUnknownPropertyDevtool); - ReactDOMDebugTool.addDevtool(ReactDOMNullInputValuePropDevtool); -} +ReactDOMDebugTool.addDevtool(ReactDOMUnknownPropertyDevtool); +ReactDOMDebugTool.addDevtool(ReactDOMNullInputValuePropDevtool); module.exports = ReactDOMDebugTool; diff --git a/src/renderers/dom/shared/ReactDOMInstrumentation.js b/src/renderers/dom/shared/ReactDOMInstrumentation.js index b290c6c553cf0..4f31a7818dd36 100644 --- a/src/renderers/dom/shared/ReactDOMInstrumentation.js +++ b/src/renderers/dom/shared/ReactDOMInstrumentation.js @@ -11,6 +11,11 @@ 'use strict'; -var ReactDOMDebugTool = require('ReactDOMDebugTool'); +var debugTool = null; -module.exports = {debugTool: ReactDOMDebugTool}; +if (__DEV__) { + var ReactDOMDebugTool = require('ReactDOMDebugTool'); + debugTool = ReactDOMDebugTool; +} + +module.exports = {debugTool}; diff --git a/src/renderers/shared/ReactDebugTool.js b/src/renderers/shared/ReactDebugTool.js index f386cd21e69df..62113ba8de05f 100644 --- a/src/renderers/shared/ReactDebugTool.js +++ b/src/renderers/shared/ReactDebugTool.js @@ -11,6 +11,10 @@ 'use strict'; +var ReactInvalidSetStateWarningDevTool = require('ReactInvalidSetStateWarningDevTool'); +var ReactHostOperationHistoryDevtool = require('ReactHostOperationHistoryDevtool'); +var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool'); +var ReactChildrenMutationWarningDevtool = require('ReactChildrenMutationWarningDevtool'); var ExecutionEnvironment = require('ExecutionEnvironment'); var performanceNow = require('performanceNow'); @@ -20,23 +24,21 @@ var eventHandlers = []; var handlerDoesThrowForEvent = {}; function emitEvent(handlerFunctionName, arg1, arg2, arg3, arg4, arg5) { - if (__DEV__) { - eventHandlers.forEach(function(handler) { - try { - if (handler[handlerFunctionName]) { - handler[handlerFunctionName](arg1, arg2, arg3, arg4, arg5); - } - } catch (e) { - warning( - handlerDoesThrowForEvent[handlerFunctionName], - 'exception thrown by devtool while handling %s: %s', - handlerFunctionName, - e + '\n' + e.stack - ); - handlerDoesThrowForEvent[handlerFunctionName] = true; + eventHandlers.forEach(function(handler) { + try { + if (handler[handlerFunctionName]) { + handler[handlerFunctionName](arg1, arg2, arg3, arg4, arg5); } - }); - } + } catch (e) { + warning( + handlerDoesThrowForEvent[handlerFunctionName], + 'exception thrown by devtool while handling %s: %s', + handlerFunctionName, + e + '\n' + e.stack + ); + handlerDoesThrowForEvent[handlerFunctionName] = true; + } + }); } var isProfiling = false; @@ -73,32 +75,30 @@ function getTreeSnapshot(registeredIDs) { } function resetMeasurements() { - if (__DEV__) { - var previousStartTime = currentFlushStartTime; - var previousMeasurements = currentFlushMeasurements || []; - var previousOperations = ReactHostOperationHistoryDevtool.getHistory(); - - if (!isProfiling || currentFlushNesting === 0) { - currentFlushStartTime = null; - currentFlushMeasurements = null; - clearHistory(); - return; - } - - if (previousMeasurements.length || previousOperations.length) { - var registeredIDs = ReactComponentTreeDevtool.getRegisteredIDs(); - flushHistory.push({ - duration: performanceNow() - previousStartTime, - measurements: previousMeasurements || [], - operations: previousOperations || [], - treeSnapshot: getTreeSnapshot(registeredIDs), - }); - } + var previousStartTime = currentFlushStartTime; + var previousMeasurements = currentFlushMeasurements || []; + var previousOperations = ReactHostOperationHistoryDevtool.getHistory(); + if (!isProfiling || currentFlushNesting === 0) { + currentFlushStartTime = null; + currentFlushMeasurements = null; clearHistory(); - currentFlushStartTime = performanceNow(); - currentFlushMeasurements = []; + return; + } + + if (previousMeasurements.length || previousOperations.length) { + var registeredIDs = ReactComponentTreeDevtool.getRegisteredIDs(); + flushHistory.push({ + duration: performanceNow() - previousStartTime, + measurements: previousMeasurements || [], + operations: previousOperations || [], + treeSnapshot: getTreeSnapshot(registeredIDs), + }); } + + clearHistory(); + currentFlushStartTime = performanceNow(); + currentFlushMeasurements = []; } function checkDebugID(debugID) { @@ -187,57 +187,45 @@ var ReactDebugTool = { return isProfiling; }, beginProfiling() { - if (__DEV__) { - if (isProfiling) { - return; - } - - isProfiling = true; - flushHistory.length = 0; - resetMeasurements(); + if (isProfiling) { + return; } + + isProfiling = true; + flushHistory.length = 0; + resetMeasurements(); }, endProfiling() { - if (__DEV__) { - if (!isProfiling) { - return; - } - - isProfiling = false; - resetMeasurements(); + if (!isProfiling) { + return; } + + isProfiling = false; + resetMeasurements(); }, getFlushHistory() { return flushHistory; }, onBeginFlush() { - if (__DEV__) { - currentFlushNesting++; - resetMeasurements(); - pauseCurrentLifeCycleTimer(); - } + currentFlushNesting++; + resetMeasurements(); + pauseCurrentLifeCycleTimer(); emitEvent('onBeginFlush'); }, onEndFlush() { - if (__DEV__) { - resetMeasurements(); - currentFlushNesting--; - resumeCurrentLifeCycleTimer(); - } + resetMeasurements(); + currentFlushNesting--; + resumeCurrentLifeCycleTimer(); emitEvent('onEndFlush'); }, onBeginLifeCycleTimer(debugID, timerType) { checkDebugID(debugID); emitEvent('onBeginLifeCycleTimer', debugID, timerType); - if (__DEV__) { - beginLifeCycleTimer(debugID, timerType); - } + beginLifeCycleTimer(debugID, timerType); }, onEndLifeCycleTimer(debugID, timerType) { checkDebugID(debugID); - if (__DEV__) { - endLifeCycleTimer(debugID, timerType); - } + endLifeCycleTimer(debugID, timerType); emitEvent('onEndLifeCycleTimer', debugID, timerType); }, onBeginReconcilerTimer(debugID, timerType) { @@ -318,19 +306,13 @@ var ReactDebugTool = { }, }; -if (__DEV__) { - var ReactInvalidSetStateWarningDevTool = require('ReactInvalidSetStateWarningDevTool'); - var ReactHostOperationHistoryDevtool = require('ReactHostOperationHistoryDevtool'); - var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool'); - var ReactChildrenMutationWarningDevtool = require('ReactChildrenMutationWarningDevtool'); - ReactDebugTool.addDevtool(ReactInvalidSetStateWarningDevTool); - ReactDebugTool.addDevtool(ReactComponentTreeDevtool); - ReactDebugTool.addDevtool(ReactHostOperationHistoryDevtool); - ReactDebugTool.addDevtool(ReactChildrenMutationWarningDevtool); - var url = (ExecutionEnvironment.canUseDOM && window.location.href) || ''; - if ((/[?&]react_perf\b/).test(url)) { - ReactDebugTool.beginProfiling(); - } +ReactDebugTool.addDevtool(ReactInvalidSetStateWarningDevTool); +ReactDebugTool.addDevtool(ReactComponentTreeDevtool); +ReactDebugTool.addDevtool(ReactHostOperationHistoryDevtool); +ReactDebugTool.addDevtool(ReactChildrenMutationWarningDevtool); +var url = (ExecutionEnvironment.canUseDOM && window.location.href) || ''; +if ((/[?&]react_perf\b/).test(url)) { + ReactDebugTool.beginProfiling(); } module.exports = ReactDebugTool; diff --git a/src/renderers/shared/ReactInstrumentation.js b/src/renderers/shared/ReactInstrumentation.js index 066da6aaae823..08419bc0e2961 100644 --- a/src/renderers/shared/ReactInstrumentation.js +++ b/src/renderers/shared/ReactInstrumentation.js @@ -11,6 +11,11 @@ 'use strict'; -var ReactDebugTool = require('ReactDebugTool'); +var debugTool = null; -module.exports = {debugTool: ReactDebugTool}; +if (__DEV__) { + var ReactDebugTool = require('ReactDebugTool'); + debugTool = ReactDebugTool; +} + +module.exports = {debugTool};