Created
June 12, 2019 12:01
-
-
Save matthewp/6830c5997a81a0020103cb28f5164c71 to your computer and use it in GitHub Desktop.
Observed attributes dynamic
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"> | |
<title>Some title</title> | |
<my-element id="myel"><my-element> | |
<script type="module"> | |
class MyElement extends HTMLElement { | |
static get observedAttributes() { | |
let defines = this.define; | |
let attrs = []; | |
for(let [prop, definition] of Object.entries(defines)) { | |
if(definition.attribute) { | |
attrs.push(prop); | |
} | |
} | |
return attrs; | |
} | |
static get define() { | |
return { | |
foo: { | |
attribute: true | |
} | |
} | |
} | |
attributeChangedCallback(attrName, oldValue, newValue) { | |
console.log(attrName, 'changed to', newValue); | |
} | |
} | |
customElements.define('my-element', MyElement); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment