UNPKG

2.12 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'use strict';
10
11var _prodInvariant = require('./reactProdInvariant');
12
13var DOMLazyTree = require('./DOMLazyTree');
14var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
15
16var createNodesFromMarkup = require('fbjs/lib/createNodesFromMarkup');
17var emptyFunction = require('fbjs/lib/emptyFunction');
18var invariant = require('fbjs/lib/invariant');
19
20var Danger = {
21 /**
22 * Replaces a node with a string of markup at its current position within its
23 * parent. The markup must render into a single root node.
24 *
25 * @param {DOMElement} oldChild Child node to replace.
26 * @param {string} markup Markup to render in place of the child node.
27 * @internal
28 */
29 dangerouslyReplaceNodeWithMarkup: function (oldChild, markup) {
30 !ExecutionEnvironment.canUseDOM ? process.env.NODE_ENV !== 'production' ? invariant(false, 'dangerouslyReplaceNodeWithMarkup(...): Cannot render markup in a worker thread. Make sure `window` and `document` are available globally before requiring React when unit testing or use ReactDOMServer.renderToString() for server rendering.') : _prodInvariant('56') : void 0;
31 !markup ? process.env.NODE_ENV !== 'production' ? invariant(false, 'dangerouslyReplaceNodeWithMarkup(...): Missing markup.') : _prodInvariant('57') : void 0;
32 !(oldChild.nodeName !== 'HTML') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'dangerouslyReplaceNodeWithMarkup(...): Cannot replace markup of the <html> node. This is because browser quirks make this unreliable and/or slow. If you want to render to the root you must use server rendering. See ReactDOMServer.renderToString().') : _prodInvariant('58') : void 0;
33
34 if (typeof markup === 'string') {
35 var newChild = createNodesFromMarkup(markup, emptyFunction)[0];
36 oldChild.parentNode.replaceChild(newChild, oldChild);
37 } else {
38 DOMLazyTree.replaceChildWithTree(oldChild, markup);
39 }
40 }
41};
42
43module.exports = Danger;
\No newline at end of file