UNPKG

5.05 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2013-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 */
8
9/* globals __REACT_DEVTOOLS_GLOBAL_HOOK__*/
10
11'use strict';
12
13var ReactDOMComponentTree = require('./ReactDOMComponentTree');
14var ReactDefaultInjection = require('./ReactDefaultInjection');
15var ReactMount = require('./ReactMount');
16var ReactReconciler = require('./ReactReconciler');
17var ReactUpdates = require('./ReactUpdates');
18var ReactVersion = require('./ReactVersion');
19
20var findDOMNode = require('./findDOMNode');
21var getHostComponentFromComposite = require('./getHostComponentFromComposite');
22var renderSubtreeIntoContainer = require('./renderSubtreeIntoContainer');
23var warning = require('fbjs/lib/warning');
24
25ReactDefaultInjection.inject();
26
27var ReactDOM = {
28 findDOMNode: findDOMNode,
29 render: ReactMount.render,
30 unmountComponentAtNode: ReactMount.unmountComponentAtNode,
31 version: ReactVersion,
32
33 /* eslint-disable camelcase */
34 unstable_batchedUpdates: ReactUpdates.batchedUpdates,
35 unstable_renderSubtreeIntoContainer: renderSubtreeIntoContainer
36 /* eslint-enable camelcase */
37};
38
39// Inject the runtime into a devtools global hook regardless of browser.
40// Allows for debugging when the hook is injected on the page.
41if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.inject === 'function') {
42 __REACT_DEVTOOLS_GLOBAL_HOOK__.inject({
43 ComponentTree: {
44 getClosestInstanceFromNode: ReactDOMComponentTree.getClosestInstanceFromNode,
45 getNodeFromInstance: function (inst) {
46 // inst is an internal instance (but could be a composite)
47 if (inst._renderedComponent) {
48 inst = getHostComponentFromComposite(inst);
49 }
50 if (inst) {
51 return ReactDOMComponentTree.getNodeFromInstance(inst);
52 } else {
53 return null;
54 }
55 }
56 },
57 Mount: ReactMount,
58 Reconciler: ReactReconciler
59 });
60}
61
62if (process.env.NODE_ENV !== 'production') {
63 var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
64 if (ExecutionEnvironment.canUseDOM && window.top === window.self) {
65 // First check if devtools is not installed
66 if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
67 // If we're in Chrome or Firefox, provide a download link if not installed.
68 if (navigator.userAgent.indexOf('Chrome') > -1 && navigator.userAgent.indexOf('Edge') === -1 || navigator.userAgent.indexOf('Firefox') > -1) {
69 // Firefox does not have the issue with devtools loaded over file://
70 var showFileUrlMessage = window.location.protocol.indexOf('http') === -1 && navigator.userAgent.indexOf('Firefox') === -1;
71 console.debug('Download the React DevTools ' + (showFileUrlMessage ? 'and use an HTTP server (instead of a file: URL) ' : '') + 'for a better development experience: ' + 'https://fb.me/react-devtools');
72 }
73 }
74
75 var testFunc = function testFn() {};
76 process.env.NODE_ENV !== 'production' ? warning((testFunc.name || testFunc.toString()).indexOf('testFn') !== -1, "It looks like you're using a minified copy of the development build " + 'of React. When deploying React apps to production, make sure to use ' + 'the production build which skips development warnings and is faster. ' + 'See https://fb.me/react-minification for more details.') : void 0;
77
78 // If we're in IE8, check to see if we are in compatibility mode and provide
79 // information on preventing compatibility mode
80 var ieCompatibilityMode = document.documentMode && document.documentMode < 8;
81
82 process.env.NODE_ENV !== 'production' ? warning(!ieCompatibilityMode, 'Internet Explorer is running in compatibility mode; please add the ' + 'following tag to your HTML to prevent this from happening: ' + '<meta http-equiv="X-UA-Compatible" content="IE=edge" />') : void 0;
83
84 var expectedFeatures = [
85 // shims
86 Array.isArray, Array.prototype.every, Array.prototype.forEach, Array.prototype.indexOf, Array.prototype.map, Date.now, Function.prototype.bind, Object.keys, String.prototype.trim];
87
88 for (var i = 0; i < expectedFeatures.length; i++) {
89 if (!expectedFeatures[i]) {
90 process.env.NODE_ENV !== 'production' ? warning(false, 'One or more ES5 shims expected by React are not available: ' + 'https://fb.me/react-warning-polyfills') : void 0;
91 break;
92 }
93 }
94 }
95}
96
97if (process.env.NODE_ENV !== 'production') {
98 var ReactInstrumentation = require('./ReactInstrumentation');
99 var ReactDOMUnknownPropertyHook = require('./ReactDOMUnknownPropertyHook');
100 var ReactDOMNullInputValuePropHook = require('./ReactDOMNullInputValuePropHook');
101 var ReactDOMInvalidARIAHook = require('./ReactDOMInvalidARIAHook');
102
103 ReactInstrumentation.debugTool.addHook(ReactDOMUnknownPropertyHook);
104 ReactInstrumentation.debugTool.addHook(ReactDOMNullInputValuePropHook);
105 ReactInstrumentation.debugTool.addHook(ReactDOMInvalidARIAHook);
106}
107
108module.exports = ReactDOM;
\No newline at end of file