mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
d310d654a7
I'm trying to get rid of all meta programming in the module scope so
that closure can do a better job figuring out cyclic dependencies and
ability to reorder.
This is converting a lot of the patterns that assign functions
conditionally to using function declarations instead.
```
let fn;
if (__DEV__) {
fn = function() {
...
};
}
```
->
```
function fn() {
if (__DEV__) {
...
}
}
```
38 lines
893 B
JavaScript
38 lines
893 B
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
import {TEXT_NODE} from './HTMLNodeType';
|
|
|
|
/**
|
|
* Set the textContent property of a node. For text updates, it's faster
|
|
* to set the `nodeValue` of the Text node directly instead of using
|
|
* `.textContent` which will remove the existing node and create a new one.
|
|
*
|
|
* @param {DOMElement} node
|
|
* @param {string} text
|
|
* @internal
|
|
*/
|
|
function setTextContent(node: Element, text: string): void {
|
|
if (text) {
|
|
const firstChild = node.firstChild;
|
|
|
|
if (
|
|
firstChild &&
|
|
firstChild === node.lastChild &&
|
|
firstChild.nodeType === TEXT_NODE
|
|
) {
|
|
firstChild.nodeValue = text;
|
|
return;
|
|
}
|
|
}
|
|
node.textContent = text;
|
|
}
|
|
|
|
export default setTextContent;
|