Move style loading monitor to class

This commit is contained in:
Matt Bierner
2018-03-05 11:15:02 -08:00
parent dc0d6badd3
commit 5ef492b88d
2 changed files with 27 additions and 20 deletions

View File

@@ -4,24 +4,28 @@
*--------------------------------------------------------------------------------------------*/
import { postCommand } from './messaging';
const unloadedStyles: string[] = [];
export class StyleLoadingMonitor {
private unloadedStyles: string[] = [];
const onStyleLoadError = (event: any) => {
const source = event.target.dataset.source;
unloadedStyles.push(source);
};
constructor() {
const onStyleLoadError = (event: any) => {
const source = event.target.dataset.source;
this.unloadedStyles.push(source);
};
window.addEventListener('DOMContentLoaded', () => {
for (const link of document.getElementsByClassName('code-user-style') as HTMLCollectionOf<HTMLElement>) {
if (link.dataset.source) {
link.onerror = onStyleLoadError;
}
window.addEventListener('DOMContentLoaded', () => {
for (const link of document.getElementsByClassName('code-user-style') as HTMLCollectionOf<HTMLElement>) {
if (link.dataset.source) {
link.onerror = onStyleLoadError;
}
}
});
window.addEventListener('load', () => {
if (!this.unloadedStyles.length) {
return;
}
postCommand('_markdown.onPreviewStyleLoadError', [this.unloadedStyles]);
});
}
});
window.addEventListener('load', () => {
if (!unloadedStyles.length) {
return;
}
postCommand('_markdown.onPreviewStyleLoadError', [unloadedStyles]);
});
}