mirror of
https://github.com/wassname/template.git
synced 2026-07-10 15:00:36 +08:00
Minor perf tweaks
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user