From ce19af9d304bb0b2c9b3fabf6b999c45be5b7b72 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Mon, 13 Oct 2014 11:59:23 -0700 Subject: [PATCH] Inject the runtime to a global instead of exposing internals See https://github.com/facebook/react-devtools/commit/673de20a4a0654ab849575307b9cf87fde53439e --- src/browser/ui/React.js | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/browser/ui/React.js b/src/browser/ui/React.js index 1f90a3a9f7..382cc89f1d 100644 --- a/src/browser/ui/React.js +++ b/src/browser/ui/React.js @@ -83,16 +83,6 @@ var React = { isValidClass: ReactLegacyElement.isValidFactory, isValidElement: ReactElement.isValidElement, withContext: ReactContext.withContext, - __internals: { - Component: ReactComponent, - CurrentOwner: ReactCurrentOwner, - DOMComponent: ReactDOMComponent, - DOMPropertyOperations: DOMPropertyOperations, - InstanceHandles: ReactInstanceHandles, - Mount: ReactMount, - MultiChild: ReactMultiChild, - TextComponent: ReactTextComponent - }, // Deprecations (remove for 0.13) renderComponent: deprecated( @@ -125,18 +115,36 @@ var React = { ) }; +// Inject the runtime into a devtools global hook regardless of browser. +// Allows for debugging when the hook is injected on the page. +if ( + typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && + typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.inject === 'function') { + __REACT_DEVTOOLS_GLOBAL_HOOK__.inject({ + Component: ReactComponent, + CurrentOwner: ReactCurrentOwner, + DOMComponent: ReactDOMComponent, + DOMPropertyOperations: DOMPropertyOperations, + InstanceHandles: ReactInstanceHandles, + Mount: ReactMount, + MultiChild: ReactMultiChild, + TextComponent: ReactTextComponent + }); +} + if (__DEV__) { var ExecutionEnvironment = require('ExecutionEnvironment'); if (ExecutionEnvironment.canUseDOM && window.top === window.self) { // If we're in Chrome, look for the devtools marker and provide a download // link if not installed. - if (navigator.userAgent.indexOf('Chrome') > -1 && - typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') { - console.debug( - 'If you haven\'t already, download the React DevTools for a better ' + - 'development experience: http://fb.me/react-devtools' - ); + if (navigator.userAgent.indexOf('Chrome') > -1) { + if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') { + console.debug( + 'Download the React DevTools for a better development experience: ' + + 'http://fb.me/react-devtools' + ); + } } var expectedFeatures = [