Skip to content

Commit

Permalink
Add a nonintuitive disconnectedCallback example
Browse files Browse the repository at this point in the history
Supersedes and closes #4127. Closes WICG/webcomponents#760.
  • Loading branch information
annevk committed Dec 13, 2018
1 parent edc1e95 commit 7158112
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -66945,6 +66945,34 @@ customElements.define("x-foo", class extends HTMLElement {
reaction</span> code can perform its own mutations, it is not possible to give a global ordering
guarantee across multiple elements.)</p>

<div class="example">
<p>An element's <code data-x="">connectedCallback</code> can be queued before the element is
disconnected, but as the callback queue is still processed, it results in a <code
data-x="">connectedCallback</code> for an element that is no longer connected:</p>

<pre><code class="js" data-x="">class CParent extends HTMLElement {
connectedCallback() {
this.firstChild.remove();
}
}
customElements.define("c-parent", CParent);

class CChild extends HTMLElement {
connectedCallback() {
console.log("CChild connectedCallback: isConnected =", this.isConnected);
}
}
customElements.define("c-child", CChild);

const container = document.createElement("div");
container.innerHTML = "&lt;c-parent>&lt;c-child>&lt;/c-child>&lt;/c-parent>";
customElements.upgrade(container);
document.body.appendChild(container);

// Logs:
// CChild connectedCallback: isConnected = false</code></pre>
</div>

<div w-nodev>

<hr>
Expand Down Expand Up @@ -122593,6 +122621,7 @@ INSERT INTERFACES HERE
Tom Pike,
Tom Schuster,
Tomasz Jakut, <!-- Comandeer on GitHub -->
Tomek Wytrębowicz,
Tommy Thorsen,
Tony Ross,
Tooru Fujisawa,
Expand Down

0 comments on commit 7158112

Please sign in to comment.