- From: Allen Kim <notifications@github.com>
- Date: Sun, 19 Nov 2017 22:49:32 +0000 (UTC)
- To: w3c/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Sunday, 19 November 2017 22:49:55 UTC
For my case, I ended up with building my own instead of using `observedAttributes` and `attributeChangedCallback()` because;
1. I wanted to observe all attribute changes instead of few.
2. and, the list of attributes to observe are not limited, but dynamic. (e.g. google maps attribute.)
What I do is to simply call this from `connectedCallback`
```
function observeAttrChange(el, callback) {
var observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.type === 'attributes') {
let newVal = mutation.target.getAttribute(mutation.attributeName);
callback(mutation.attributeName, newVal);
}
});
});
observer.observe(el, {attributes: true});
return observer;
}
```
```
connectedCallback() {
observeAttrChange(this, ....);
}
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/565#issuecomment-345556883
Received on Sunday, 19 November 2017 22:49:55 UTC