From 9d180de631c24c2e4a8a9115c0ead75a57cd8504 Mon Sep 17 00:00:00 2001 From: Ludwig Schubert Date: Thu, 24 Aug 2017 10:30:36 -0700 Subject: [PATCH] Minor perf tweaks --- src/components/d-figure.js | 14 ++++++++------ src/components/d-front-matter.js | 12 ++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/components/d-figure.js b/src/components/d-figure.js index aa4e2d1..571612a 100644 --- a/src/components/d-figure.js +++ b/src/components/d-figure.js @@ -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 diff --git a/src/components/d-front-matter.js b/src/components/d-front-matter.js index 13ce892..b47b0b2 100644 --- a/src/components/d-front-matter.js +++ b/src/components/d-front-matter.js @@ -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); }