Skip to content

Commit

Permalink
Add whenDefined callback constructor value test.
Browse files Browse the repository at this point in the history
  • Loading branch information
sanketj committed Jan 28, 2025
1 parent 351ea22 commit a26b6a6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions components/whenDefined-callback-constructor-value.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<style></style>
</head>
<body>
<my-element></my-element>
<script>
window.customElements.whenDefined('my-element').then((customElementConstructor) => {
console.log(typeof customElementConstructor);
console.log(customElementConstructor + ' is defined');
document.body.append(new customElementConstructor());
});
class MyElement extends HTMLElement {
constructor() {
super();
this.attachShadow({mode: 'open'});
this.shadowRoot.innerHTML = '<span>abc</span>';
}
}
window.setTimeout(() => {
window.customElements.define('my-element', MyElement);
}, 5000);
</script>
</body>
</html>

0 comments on commit a26b6a6

Please sign in to comment.