Created
November 16, 2020 17:06
-
-
Save AndersCan/d216a385d951f8d5ba8a0dc3373d6417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HelloElement extends HTMLElement { | |
connectedCallback() { | |
this.innerHTML = this.render('Nettleser: Hei'); | |
} | |
render(text) { | |
return `<h1> ${text} </h1>`; | |
} | |
} | |
customElements.define('hello-element', HelloElement); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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