-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5451 from spicyj/empty-comments
Use comment nodes for empty components
- Loading branch information
Showing
9 changed files
with
163 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright 2014-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactDOMEmptyComponent | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var DOMLazyTree = require('DOMLazyTree'); | ||
var ReactDOMComponentTree = require('ReactDOMComponentTree'); | ||
|
||
var assign = require('Object.assign'); | ||
|
||
var ReactDOMEmptyComponent = function(instantiate) { | ||
// ReactCompositeComponent uses this: | ||
this._currentElement = null; | ||
// ReactDOMComponentTree uses these: | ||
this._nativeNode = null; | ||
this._nativeParent = null; | ||
this._nativeContainerInfo = null; | ||
this._domID = null; | ||
}; | ||
assign(ReactDOMEmptyComponent.prototype, { | ||
construct: function(element) { | ||
}, | ||
mountComponent: function( | ||
transaction, | ||
nativeParent, | ||
nativeContainerInfo, | ||
context | ||
) { | ||
var domID = nativeContainerInfo._idCounter++; | ||
this._domID = domID; | ||
this._nativeParent = nativeParent; | ||
this._nativeContainerInfo = nativeContainerInfo; | ||
|
||
var nodeValue = ' react-empty: ' + this._domID + ' '; | ||
if (transaction.useCreateElement) { | ||
var ownerDocument = nativeContainerInfo._ownerDocument; | ||
var node = ownerDocument.createComment(nodeValue); | ||
ReactDOMComponentTree.precacheNode(this, node); | ||
return DOMLazyTree(node); | ||
} else { | ||
if (transaction.renderToStaticMarkup) { | ||
// Normally we'd insert a comment node, but since this is a situation | ||
// where React won't take over (static pages), we can simply return | ||
// nothing. | ||
return ''; | ||
} | ||
return '<!--' + nodeValue + '-->'; | ||
} | ||
}, | ||
receiveComponent: function() { | ||
}, | ||
getNativeNode: function() { | ||
return ReactDOMComponentTree.getNodeFromInstance(this); | ||
}, | ||
unmountComponent: function() { | ||
ReactDOMComponentTree.uncacheNode(this); | ||
}, | ||
}); | ||
|
||
module.exports = ReactDOMEmptyComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/renderers/shared/reconciler/ReactSimpleEmptyComponent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright 2014-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactSimpleEmptyComponent | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var ReactReconciler = require('ReactReconciler'); | ||
|
||
var assign = require('Object.assign'); | ||
|
||
var ReactSimpleEmptyComponent = function(placeholderElement, instantiate) { | ||
this._currentElement = null; | ||
this._renderedComponent = instantiate(placeholderElement); | ||
}; | ||
assign(ReactSimpleEmptyComponent.prototype, { | ||
construct: function(element) { | ||
}, | ||
mountComponent: function( | ||
transaction, | ||
nativeParent, | ||
nativeContainerInfo, | ||
context | ||
) { | ||
return ReactReconciler.mountComponent( | ||
this._renderedComponent, | ||
transaction, | ||
nativeParent, | ||
nativeContainerInfo, | ||
context | ||
); | ||
}, | ||
receiveComponent: function() { | ||
}, | ||
getNativeNode: function() { | ||
return ReactReconciler.getNativeNode(this._renderedComponent); | ||
}, | ||
unmountComponent: function() { | ||
ReactReconciler.unmountComponent(this._renderedComponent); | ||
this._renderedComponent = null; | ||
}, | ||
}); | ||
|
||
module.exports = ReactSimpleEmptyComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters