Hi all,
The context for this is Polymer Dart, but @jmesserly thinks this is probably a generic Shadow DOM + Mutation Observers question, so I'm asking here.
I'm trying to observe mutations in the distributed content of a <content> tag as follows:
@CustomTag(inner-element')
class MyElement {
void enteredView() {
new MutationObserver((m, o) => print("content changed")).observe(this, childList: true);
}
};
That works when I use it like this:
<inner-element>
<template repeat="{{x in xs}}">
{{x}}
</>
</>
But it breaks when there is another element that wraps around and reprojects its distributed content into <inner-element>:
<polymer-element name="outer-element">
<template>
<inner-element>
<content></content>
</inner-element>
</>
</>
<outer-element>
<template repeat="{{x in xs}}">
{{x}}
</>
</>
InnerElement does not see the changes in the xs. What it is the right way to observe them? Ideally, I'd like it to be generic, i.e. working for both cases above. As a less preferred option, I could implement a special case for when the distributed content is a reprojected <content> from the embedder.
I could of course add a second MutationObserver to OuterElement and explicitly tell InnerElement to update whenever a mutation happens, but it seems to me that this defies the whole idea of MutationObservers.
Thanks,
--Sergey