DEV Community

Discussion on: Building Web Components with Vanilla JavaScript

Collapse
 
thatjoemoore profile image
Joseph Moore

For performance reasons, the browsers require you to define the list of attributes you want to listen to. You can do that by defining a static method called observedAttributes, which returns an array:

static get observedAttributes() {return ['my-attr', 'another-value']; }

That'll cause attributeChangedCallback to fire for changes to either of the listed attributes.

Collapse
 
maccabee profile image
Maccabee

Thanks a lot. I did get it to work with a setter but i still wanted to know how the callback works. I'll try it out when I can.