Skip to content

Instantly share code, notes, and snippets.

@nicolasparada
Last active November 21, 2016 11:42
Show Gist options
  • Save nicolasparada/e43f629b0e0f92c9ce30abfd16a0305f to your computer and use it in GitHub Desktop.
Save nicolasparada/e43f629b0e0f92c9ce30abfd16a0305f to your computer and use it in GitHub Desktop.
Custom Element: Hello, world!
// 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)
@nicolasparada
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment