UNPKG

5.17 kBJavaScriptView Raw
1/**
2 * Copyright 2013-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
8 *
9 */
10
11/* globals __REACT_DEVTOOLS_GLOBAL_HOOK__*/
12
13'use strict';
14
15var ReactDOMComponentTree = require('./ReactDOMComponentTree');
16var ReactDefaultInjection = require('./ReactDefaultInjection');
17var ReactMount = require('./ReactMount');
18var ReactReconciler = require('./ReactReconciler');
19var ReactUpdates = require('./ReactUpdates');
20var ReactVersion = require('./ReactVersion');
21
22var findDOMNode = require('./findDOMNode');
23var getHostComponentFromComposite = require('./getHostComponentFromComposite');
24var renderSubtreeIntoContainer = require('./renderSubtreeIntoContainer');
25var warning = require('fbjs/lib/warning');
26
27ReactDefaultInjection.inject();
28
29var ReactDOM = {
30 findDOMNode: findDOMNode,
31 render: ReactMount.render,
32 unmountComponentAtNode: ReactMount.unmountComponentAtNode,
33 version: ReactVersion,
34
35 /* eslint-disable camelcase */
36 unstable_batchedUpdates: ReactUpdates.batchedUpdates,
37 unstable_renderSubtreeIntoContainer: renderSubtreeIntoContainer
38 /* eslint-enable camelcase */
39};
40
41// Inject the runtime into a devtools global hook regardless of browser.
42// Allows for debugging when the hook is injected on the page.
43if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.inject === 'function') {
44 __REACT_DEVTOOLS_GLOBAL_HOOK__.inject({
45 ComponentTree: {
46 getClosestInstanceFromNode: ReactDOMComponentTree.getClosestInstanceFromNode,
47 getNodeFromInstance: function (inst) {
48 // inst is an internal instance (but could be a composite)
49 if (inst._renderedComponent) {
50 inst = getHostComponentFromComposite(inst);
51 }
52 if (inst) {
53 return ReactDOMComponentTree.getNodeFromInstance(inst);
54 } else {
55 return null;
56 }
57 }
58 },
59 Mount: ReactMount,
60 Reconciler: ReactReconciler
61 });
62}
63
64if (process.env.NODE_ENV !== 'production') {
65 var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
66 if (ExecutionEnvironment.canUseDOM && window.top === window.self) {
67 // First check if devtools is not installed
68 if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
69 // If we're in Chrome or Firefox, provide a download link if not installed.
70 if (navigator.userAgent.indexOf('Chrome') > -1 && navigator.userAgent.indexOf('Edge') === -1 || navigator.userAgent.indexOf('Firefox') > -1) {
71 // Firefox does not have the issue with devtools loaded over file://
72 var showFileUrlMessage = window.location.protocol.indexOf('http') === -1 && navigator.userAgent.indexOf('Firefox') === -1;
73 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');
74 }
75 }
76
77 var testFunc = function testFn() {};
78 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;
79
80 // If we're in IE8, check to see if we are in compatibility mode and provide
81 // information on preventing compatibility mode
82 var ieCompatibilityMode = document.documentMode && document.documentMode < 8;
83
84 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;
85
86 var expectedFeatures = [
87 // shims
88 Array.isArray, Array.prototype.every, Array.prototype.forEach, Array.prototype.indexOf, Array.prototype.map, Date.now, Function.prototype.bind, Object.keys, String.prototype.trim];
89
90 for (var i = 0; i < expectedFeatures.length; i++) {
91 if (!expectedFeatures[i]) {
92 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;
93 break;
94 }
95 }
96 }
97}
98
99if (process.env.NODE_ENV !== 'production') {
100 var ReactInstrumentation = require('./ReactInstrumentation');
101 var ReactDOMUnknownPropertyHook = require('./ReactDOMUnknownPropertyHook');
102 var ReactDOMNullInputValuePropHook = require('./ReactDOMNullInputValuePropHook');
103 var ReactDOMInvalidARIAHook = require('./ReactDOMInvalidARIAHook');
104
105 ReactInstrumentation.debugTool.addHook(ReactDOMUnknownPropertyHook);
106 ReactInstrumentation.debugTool.addHook(ReactDOMNullInputValuePropHook);
107 ReactInstrumentation.debugTool.addHook(ReactDOMInvalidARIAHook);
108}
109
110module.exports = ReactDOM;
\No newline at end of file