amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-bind: Don't depend on template element's presence inside dynamic elements

Open kmh287 opened this issue 9 years ago • 3 comments

For instance, amp-list allows developers to specify the id of a template rather than including it as a descendant of the amp-list element. Under the current strategy, if a developer puts a template as a child of the body tag, bind will observe the body tag for mutations to its children.

We should change bind to not depend on a template's position to determine which elements to observe for mutations. That means depending on the element using the template (form, amp-list etc.) rather than the template to determine what to observe. Some potential solutions for forms are:

1: Keep the same strategy we have now if a template is a descendant of a form tag. Since forms must have templates as descendants of their <div success> and <div error> elements (if they exist), the current strategy would work as-is. 2: Specifically look for the success and error divs and observe them for mutations to their children.

@choumx what are your thoughts on this?

kmh287 avatar Mar 23 '17 14:03 kmh287

If templates can be declared anywhere, we shouldn't rely on their location (perhaps forms will support template-by-id at some point). So (2) is the right strategy, though as mentioned previously it's best if delegated to the dynamic component itself.

dreamofabear avatar Mar 23 '17 15:03 dreamofabear

Could we accomplish that with an override-able method on base element? For instance, a method that returns an array of elements that should be observed for changes in their descendants.

kmh287 avatar Mar 23 '17 15:03 kmh287

And custom-element.js to forward it to the implementation object. You can see mutatedAttributesCallback as an example.

dreamofabear avatar Mar 23 '17 15:03 dreamofabear