wp-optimize
/
vendor
/
team-updraft
/
common-libs
/
src
/
updraft-theme
/
helpers
/
tu-html-element.js
tu-html-element.js in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 4.7.0, at vendor/team-updraft/common-libs/src/updraft-theme/helpers/tu-html-element.js
| 1 | export class TUHTMLElement extends HTMLElement { |
| 2 | tuRenderObserver = new MutationObserver(() => { |
| 3 | this.tuRenderObserver.disconnect(); |
| 4 | |
| 5 | // If the component has render function then render it. |
| 6 | if (this.render) { |
| 7 | this.render(); |
| 8 | } |
| 9 | }); |
| 10 | |
| 11 | /** |
| 12 | * Disconnected callback. |
| 13 | */ |
| 14 | disconnectedCallback() { |
| 15 | if (super.disconnectedCallback) { |
| 16 | super.disconnectedCallback(); |
| 17 | } |
| 18 | |
| 19 | this.tuRenderObserver.disconnect(); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Connected callback. |
| 24 | */ |
| 25 | connectedCallback() { |
| 26 | if (super.connectedCallback) { |
| 27 | super.connectedCallback(); |
| 28 | } |
| 29 | |
| 30 | // Try to render the component. |
| 31 | if (this.render) { |
| 32 | this.render(); |
| 33 | } |
| 34 | |
| 35 | // If no child nodes present, then observe for changes in the child nodes and run the renderer when they are rendered. |
| 36 | if (!this.hasChildNodes()) { |
| 37 | this.tuRenderObserver.observe(this, { subtree: true, childList: true, characterData: true }); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 |