Skip to content

Instantly share code, notes, and snippets.

@deebloo
Last active March 17, 2020 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deebloo/4bf55a4eb702aa72fe992457bc5e4730 to your computer and use it in GitHub Desktop.
Save deebloo/4bf55a4eb702aa72fe992457bc5e4730 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Element</title>
</head>
<body>
<script type="module">
import { html, render } from 'https://unpkg.com/lit-html?module';
class MyElement extends HTMLElement {
constructor(counterState) {
this.appState = appState
}
attachedCallback() {
this.render();
}
render() {
render(html`
<button @click=${() => this.counterState.decrement()}>-</button>
${this.counterState.counter}
<button @click=${() => this.counterState.increment()}>+</button>
`)
}
}
const counterState = {
counter: 0,
increment() {
this.counter++;
},
removeTodo(index) {
this.counter--;
}
}
customElements.define('my-element', new Proxy(MyElement, {
construct(target, _args, extended) {
return Reflect.construct(target, [counterState], extended)
}
}));
</script>
<my-element></my-element>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment