Skip to content

Instantly share code, notes, and snippets.

@web-padawan
Last active November 10, 2020 12:53
Show Gist options
  • Save web-padawan/3d64d993dafa7a7b3bbefd0c3768ce07 to your computer and use it in GitHub Desktop.
Save web-padawan/3d64d993dafa7a7b3bbefd0c3768ce07 to your computer and use it in GitHub Desktop.
const $value = Symbol('value');
class MyElement extends HTMLElement {
static get observedAttributes() {
return ['value'];
}
set value(value) {
this[$value] = value;
}
get value() {
return this[$value];
}
attributeChangedCallback(attr, oldValue, newValue) {
if (oldValue !== newValue) {
this[attr] = newValue;
}
}
}
customElements.define('my-element', MyElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment