* 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
(node: Element, text: string)
| 19 | * @internal |
| 20 | */ |
| 21 | function setTextContent(node: Element, text: string): void { |
| 22 | if (text) { |
| 23 | const firstChild = node.firstChild; |
| 24 | |
| 25 | if ( |
| 26 | firstChild && |
| 27 | firstChild === node.lastChild && |
| 28 | firstChild.nodeType === TEXT_NODE |
| 29 | ) { |
| 30 | firstChild.nodeValue = text; |
| 31 | return; |
| 32 | } |
| 33 | } |
| 34 | node.textContent = text; |
| 35 | } |
| 36 | |
| 37 | export default setTextContent; |
no outgoing calls
no test coverage detected