Skip to content

Instantly share code, notes, and snippets.

@AndersCan
Created November 16, 2020 17:06
Show Gist options
  • Save AndersCan/d216a385d951f8d5ba8a0dc3373d6417 to your computer and use it in GitHub Desktop.
Save AndersCan/d216a385d951f8d5ba8a0dc3373d6417 to your computer and use it in GitHub Desktop.
class HelloElement extends HTMLElement {
connectedCallback() {
this.innerHTML = this.render('Nettleser: Hei');
}
render(text) {
return `<h1> ${text} </h1>`;
}
}
customElements.define('hello-element', HelloElement);
global.HTMLElement = class EmptyHTMLElement {};
const helloElement = new HelloElement();
const serverHtml = `
<hello-element>
${helloElement.render('Server: Hei')}
</hello-element>`;
function renderElement(elementConstructor, tagName, props) {
const element = new elementConstructor();
const html = element.render(props);
return `<${tagName}> ${html} </${tagName}>`;
}
const html = renderElement(HelloElement, 'hello-element', 'Server: Hei');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment