ampproject / amp-react-prototype

A scratch pad to experiment with React rendered AMP Components
Apache License 2.0
36 stars 9 forks source link

Children attribute mutations #53

Open dvoytenko opened 4 years ago

dvoytenko commented 4 years ago

Most of composite elements would want to know their children, which can be easily monitored using mutation observer:

mutationObserver.observe(this.element, {childList: true});

This works well when the component does not differentiate the types of children. E.g. "all children are carousel's slides". When children have different designations we can use attributes to assign them different roles. For instance, a customized "next" button in the carousel can be marked up as <button arrow-next>. If these attributes can change after the initialization, we may need to observe each child for attribute changes as well. E.g.

mutationObserver.observe(child, {attributes: true, attributesFilter: ...});

The goal is to avoid this as much as possible given the additional performance and code management cost.