I modified one the Dart polymer example to test MutationObserver. It does not work! Any suggestion?
This is the HTML code:
It doesn't appear that mutation observer events can cross the shadow boundary.
If you put the into a custom element, the mutation observers will work.
Here is an example:
import 'package:polymer/polymer.dart';
import 'dart:html';
import 'dart:async';
@CustomTag("my-element")
class MyElement extends PolymerElement with ObservableMixin {
final List timestamps = toObservable([]);
MutationObserver observer;
created() {
super.created();
observer = new MutationObserver(_onMutation);
observer.observe(getShadowRoot('my-element').query('#timestamps'), childList: true, subtree: true);
new Timer.periodic(const Duration(seconds: 1), (t) {
timestamps.add(new DateTime.now().toString());
});
}
// Bindings, like repeat, happen asynchronously. To be notified
// when the shadow root's tree is modified, use a MutationObserver.
_onMutation(List mutations, MutationObserver observer) {
print('${mutations.length} mutations occurred, the first to ${mutations[0].target}');
}
}
The custom element:
- {{ts}}
The main HTML:
index