Last active
November 21, 2016 11:42
-
-
Save nicolasparada/e43f629b0e0f92c9ce30abfd16a0305f to your computer and use it in GitHub Desktop.
Custom Element: Hello, world!
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
// import diff from 'diffhtml' | |
class HelloWorld extends HTMLElement { | |
constructor() { | |
super() | |
this.name = 'world' | |
this.render = this.render.bind(this) | |
this.onInput = this.onInput.bind(this) | |
this.render() | |
} | |
onInput(ev) { | |
this.name = ev.target.value.trim() | |
this.render() | |
} | |
render() { | |
diff.innerHTML(this, diff.html` | |
<div> | |
<input type="text" placeholder="Name" oninput="${this.onInput}"> | |
<p>Hello, <span>${this.name}</span>!</p> | |
</div> | |
`) | |
} | |
} | |
customElements.define('hello-world', HelloWorld) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
diffhtml