UNPKG

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