Minor perf tweaks

This commit is contained in:
Ludwig Schubert
2017-08-24 10:30:36 -07:00
parent 8d23e288ae
commit 9d180de631
2 changed files with 16 additions and 10 deletions
+8 -6
View File
@@ -87,12 +87,14 @@ export class Figure extends HTMLElement {
addEventListener(eventName, callback) {
super.addEventListener(eventName, callback);
// if we had already dispatched something while presumingly no one was listening, we do so again
if (this._ready && eventName === 'ready') {
this.ready();
}
if (this._onscreen && eventName === 'onscreen') {
this.onscreen();
}
setTimeout(() => {
if (this._ready && eventName === 'ready') {
this.ready();
}
if (this._onscreen && eventName === 'onscreen') {
this.onscreen();
}
}, 1);
}
// Custom Events
+8 -4
View File
@@ -19,10 +19,14 @@ export class FrontMatter extends HTMLElement {
constructor() {
super();
const options = {childList: true, characterData: true, subtree: true};
const observer = new MutationObserver( () => {
const data = parseFrontmatter(this);
this.notify(data);
const options = {childList: true};
const observer = new MutationObserver( (entries) => {
for (const entry of entries) {
if (entry.target.nodeName === 'SCRIPT') {
const data = parseFrontmatter(this);
this.notify(data);
}
}
});
observer.observe(this, options);
}