LiveText.mjs (1125B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 import React from "resource://devtools/client/shared/vendor/react.mjs"; 6 import PropTypes from "resource://devtools/client/shared/vendor/react-prop-types.mjs"; 7 import ReactDOM from "resource://devtools/client/shared/vendor/react-dom.mjs"; 8 import { pre } from "resource://devtools/client/shared/vendor/react-dom-factories.mjs"; 9 10 const { Component } = React; 11 const { findDOMNode } = ReactDOM; 12 13 /** 14 * This object represents a live DOM text node in a <pre>. 15 */ 16 class LiveText extends Component { 17 static get propTypes() { 18 return { 19 data: PropTypes.instanceOf(Text), 20 }; 21 } 22 23 componentDidMount() { 24 this.componentDidUpdate(); 25 } 26 27 componentDidUpdate() { 28 const el = findDOMNode(this); 29 if (el.firstChild === this.props.data) { 30 return; 31 } 32 el.textContent = ""; 33 el.append(this.props.data); 34 } 35 36 render() { 37 return pre({ className: "data" }); 38 } 39 } 40 41 export default { LiveText };