refactor: remove duplicate initialization code in profiles (#3666)

This commit is contained in:
Sid Vishnoi 2021-07-23 16:08:19 +05:30 committed by GitHub
parent 99cdee0f27
commit ccd9f2d493
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 110 deletions

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<title>Replace me with a real title</title>
<script src="../profiles/w3c.js" async class="remove"></script>
<script src="../profiles/w3c.js" type="module" class="remove"></script>
<script class="remove">
// All config options at https://respec.org/docs/
var respecConfig = {

View File

@ -5,7 +5,7 @@
<title>
Replace me with a real title
</title>
<script src='../profiles/aom.js' async class='remove'></script>
<script src='../profiles/aom.js' type="module" class='remove'></script>
<script class='remove'>
var respecConfig = {
specStatus: "PD",

View File

@ -1,13 +1,7 @@
"use strict";
// In case everything else fails, we want the error
window.addEventListener("error", ev => {
console.error(ev.error, ev.message, ev);
});
import * as ReSpec from "../src/respec.js";
const modules = [
// order is significant
import("../src/core/base-runner.js"),
import("../src/core/ui.js"),
import("../src/core/location-hash.js"),
import("../src/core/l10n.js"),
import("../src/aom/defaults.js"),
@ -59,23 +53,6 @@ const modules = [
import("../src/core/linter-rules/no-http-props.js"),
];
async function domReady() {
if (document.readyState === "loading") {
await new Promise(resolve =>
document.addEventListener("DOMContentLoaded", resolve)
);
}
}
(async () => {
const [runner, { ui }, ...plugins] = await Promise.all(modules);
try {
ui.show();
await domReady();
await runner.runAll(plugins);
} finally {
ui.enable();
}
})().catch(err => {
console.error(err);
});
Promise.all(modules)
.then(plugins => ReSpec.run(plugins))
.catch(err => console.error(err));

View File

@ -1,13 +1,7 @@
"use strict";
// In case everything else fails, we want the error
window.addEventListener("error", ev => {
console.error(ev.error, ev.message, ev);
});
import * as ReSpec from "../src/respec.js";
const modules = [
// order is significant
import("../src/core/base-runner.js"),
import("../src/core/ui.js"),
import("../src/core/location-hash.js"),
import("../src/core/l10n.js"),
import("../src/dini/defaults.js"),
@ -59,23 +53,6 @@ const modules = [
import("../src/core/linter-rules/no-http-props.js"),
];
async function domReady() {
if (document.readyState === "loading") {
await new Promise(resolve =>
document.addEventListener("DOMContentLoaded", resolve)
);
}
}
(async () => {
const [runner, { ui }, ...plugins] = await Promise.all(modules);
try {
ui.show();
await domReady();
await runner.runAll(plugins);
} finally {
ui.enable();
}
})().catch(err => {
console.error(err);
});
Promise.all(modules)
.then(plugins => ReSpec.run(plugins))
.catch(err => console.error(err));

View File

@ -1,13 +1,7 @@
"use strict";
// In case everything else fails, we want the error
window.addEventListener("error", ev => {
console.error(ev.error, ev.message, ev);
});
import * as ReSpec from "../src/respec.js";
const modules = [
// order is significant
import("../src/core/base-runner.js"),
import("../src/core/ui.js"),
import("../src/core/location-hash.js"),
import("../src/core/l10n.js"),
import("../src/geonovum/defaults.js"),
@ -57,23 +51,6 @@ const modules = [
import("../src/core/linter-rules/no-http-props.js"),
];
async function domReady() {
if (document.readyState === "loading") {
await new Promise(resolve =>
document.addEventListener("DOMContentLoaded", resolve)
);
}
}
(async () => {
const [runner, { ui }, ...plugins] = await Promise.all(modules);
try {
ui.show();
await domReady();
await runner.runAll(plugins);
} finally {
ui.enable();
}
})().catch(err => {
console.error(err);
});
Promise.all(modules)
.then(plugins => ReSpec.run(plugins))
.catch(err => console.error(err));

View File

@ -1,13 +1,7 @@
"use strict";
// In case everything else fails, we want the error
window.addEventListener("error", ev => {
console.error(ev.error, ev.message, ev);
});
import * as ReSpec from "../src/respec.js";
const modules = [
// order is significant
import("../src/core/base-runner.js"),
import("../src/core/ui.js"),
import("../src/core/location-hash.js"),
import("../src/core/l10n.js"),
import("../src/w3c/group.js"),
@ -78,23 +72,6 @@ const modules = [
import("../src/core/linter-rules/a11y.js"),
];
async function domReady() {
if (document.readyState === "loading") {
await new Promise(resolve =>
document.addEventListener("DOMContentLoaded", resolve)
);
}
}
(async () => {
const [runner, { ui }, ...plugins] = await Promise.all(modules);
try {
ui.show();
await domReady();
await runner.runAll(plugins);
} finally {
ui.enable();
}
})().catch(err => {
console.error(err);
});
Promise.all(modules)
.then(plugins => ReSpec.run(plugins))
.catch(err => console.error(err));

25
src/respec.js Normal file
View File

@ -0,0 +1,25 @@
import { runAll } from "./core/base-runner.js";
import { ui } from "./core/ui.js";
// In case everything else fails, we want the error
window.addEventListener("error", ev => {
console.error(ev.error, ev.message, ev);
});
export async function run(plugins) {
try {
ui.show();
await domReady();
await runAll(plugins);
} finally {
ui.enable();
}
}
async function domReady() {
if (document.readyState === "loading") {
await new Promise(resolve =>
document.addEventListener("DOMContentLoaded", resolve)
);
}
}