UNPKG

2.24 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'use strict';
12
13var _prodInvariant = require('./reactProdInvariant');
14
15var DOMLazyTree = require('./DOMLazyTree');
16var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
17
18var createNodesFromMarkup = require('fbjs/lib/createNodesFromMarkup');
19var emptyFunction = require('fbjs/lib/emptyFunction');
20var invariant = require('fbjs/lib/invariant');
21
22var Danger = {
23 /**
24 * Replaces a node with a string of markup at its current position within its
25 * parent. The markup must render into a single root node.
26 *
27 * @param {DOMElement} oldChild Child node to replace.
28 * @param {string} markup Markup to render in place of the child node.
29 * @internal
30 */
31 dangerouslyReplaceNodeWithMarkup: function (oldChild, markup) {
32 !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;
33 !markup ? process.env.NODE_ENV !== 'production' ? invariant(false, 'dangerouslyReplaceNodeWithMarkup(...): Missing markup.') : _prodInvariant('57') : void 0;
34 !(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;
35
36 if (typeof markup === 'string') {
37 var newChild = createNodesFromMarkup(markup, emptyFunction)[0];
38 oldChild.parentNode.replaceChild(newChild, oldChild);
39 } else {
40 DOMLazyTree.replaceChildWithTree(oldChild, markup);
41 }
42 }
43};
44
45module.exports = Danger;
\No newline at end of file