mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
28 lines
832 B
JavaScript
28 lines
832 B
JavaScript
class CustomContainer extends HTMLElement {
|
|
constructor() {
|
|
super();
|
|
|
|
if (!this.shadowRoot) {
|
|
const shadow = this.attachShadow({ mode: 'open' });
|
|
shadow.innerHTML = '<span class="greeting">Hello unknown</span><slot></slot>';
|
|
}
|
|
|
|
this.greeting = this.shadowRoot.querySelector('.greeting');
|
|
}
|
|
|
|
divKitApiCallback({ /* logError, */ variables }) {
|
|
const nameVaraible = variables.get('name');
|
|
if (nameVaraible) {
|
|
this.unsubscribeVariable = nameVaraible.subscribe(name => {
|
|
this.greeting.textContent = `Hello ${name}`;
|
|
});
|
|
}
|
|
}
|
|
|
|
disconnectedCallback() {
|
|
this.unsubscribeVariable?.();
|
|
this.unsubscribeVariable = null;
|
|
}
|
|
}
|
|
customElements.define('custom-container', CustomContainer);
|