I'm trying to use vanilla javascript to build a custom component which observes changes in all data attributes, e.g.:
class MyComponent extends HTMLElement {
static get observedAttributes () {
return ["data-one","data-two","data-three",so forth...]
}
}
This component could in theory be assigned an arbitrary number of data attributes, so there's no way to predict exactly how many there would be, yet I need the component to do stuff every time a new data attribute is assigned to it, is there any way to do it? having to put into the array returned by "observedAttributes" the specific name of every attribute seems really restrictive
As a bonus, is there any way to observe attributes that don't have a specific name but follow a certain pattern? (e.g. they match against a regex string or something like that)
And as an extra bonus, is there any way to observe all attributes? (I know they made this not be the default behavior due to performance factors, but still it would be good to be able to enable it if needed)
observedAttributes()
vs creating a MutationObserver then? Seems like the MutationObserver is much more flexible. – Stubbed