Last active
March 17, 2020 20:22
-
-
Save deebloo/4bf55a4eb702aa72fe992457bc5e4730 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
<!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