UNPKG

1.78 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2014-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 _assign = require('object-assign');
12
13var DOMLazyTree = require('./DOMLazyTree');
14var ReactDOMComponentTree = require('./ReactDOMComponentTree');
15
16var ReactDOMEmptyComponent = function (instantiate) {
17 // ReactCompositeComponent uses this:
18 this._currentElement = null;
19 // ReactDOMComponentTree uses these:
20 this._hostNode = null;
21 this._hostParent = null;
22 this._hostContainerInfo = null;
23 this._domID = 0;
24};
25_assign(ReactDOMEmptyComponent.prototype, {
26 mountComponent: function (transaction, hostParent, hostContainerInfo, context) {
27 var domID = hostContainerInfo._idCounter++;
28 this._domID = domID;
29 this._hostParent = hostParent;
30 this._hostContainerInfo = hostContainerInfo;
31
32 var nodeValue = ' react-empty: ' + this._domID + ' ';
33 if (transaction.useCreateElement) {
34 var ownerDocument = hostContainerInfo._ownerDocument;
35 var node = ownerDocument.createComment(nodeValue);
36 ReactDOMComponentTree.precacheNode(this, node);
37 return DOMLazyTree(node);
38 } else {
39 if (transaction.renderToStaticMarkup) {
40 // Normally we'd insert a comment node, but since this is a situation
41 // where React won't take over (static pages), we can simply return
42 // nothing.
43 return '';
44 }
45 return '<!--' + nodeValue + '-->';
46 }
47 },
48 receiveComponent: function () {},
49 getHostNode: function () {
50 return ReactDOMComponentTree.getNodeFromInstance(this);
51 },
52 unmountComponent: function () {
53 ReactDOMComponentTree.uncacheNode(this);
54 }
55});
56
57module.exports = ReactDOMEmptyComponent;
\No newline at end of file