Apply async / await pattern
This commit is contained in:
parent
a28903c8b7
commit
2f349df4ec
2 changed files with 21 additions and 27 deletions
|
@ -1,8 +1,7 @@
|
||||||
import postman, { item } from "postman";
|
import postman, { item } from "postman";
|
||||||
import type { Parcel } from "postman";
|
|
||||||
import { formatNumber } from "~/lib/t";
|
import { formatNumber } from "~/lib/t";
|
||||||
|
|
||||||
(function () {
|
(async function () {
|
||||||
const docel = document.documentElement;
|
const docel = document.documentElement;
|
||||||
const main: HTMLElement = docel.querySelector(".postman.main")!;
|
const main: HTMLElement = docel.querySelector(".postman.main")!;
|
||||||
const css: HTMLStyleElement = docel.querySelector(".postman.css")!;
|
const css: HTMLStyleElement = docel.querySelector(".postman.css")!;
|
||||||
|
@ -20,7 +19,7 @@ import { formatNumber } from "~/lib/t";
|
||||||
return f;
|
return f;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const delivery = postman(
|
const parcel = await postman(
|
||||||
item.script(`/js/main/vendor.js?v=${rev}`, { id: "0" }),
|
item.script(`/js/main/vendor.js?v=${rev}`, { id: "0" }),
|
||||||
item.script(`/js/main/surah-index.js?v=${rev}`, { id: "1" }),
|
item.script(`/js/main/surah-index.js?v=${rev}`, { id: "1" }),
|
||||||
...fonts,
|
...fonts,
|
||||||
|
@ -31,14 +30,12 @@ import { formatNumber } from "~/lib/t";
|
||||||
num.innerText = formatNumber(docel.lang, Number(percent.toFixed(0)));
|
num.innerText = formatNumber(docel.lang, Number(percent.toFixed(0)));
|
||||||
}),
|
}),
|
||||||
).deliver();
|
).deliver();
|
||||||
delivery.then((parcel: Parcel) => {
|
[main, css].forEach((el) => el.remove());
|
||||||
[main, css].forEach((el) => el.remove());
|
parcel.fonts.forEach((f) => document.fonts.add(f));
|
||||||
parcel.fonts.forEach((f) => document.fonts.add(f));
|
parcel.css.forEach((s: HTMLElement) => document.head.appendChild(s));
|
||||||
parcel.css.forEach((s: HTMLElement) => document.head.appendChild(s));
|
parcel.scripts
|
||||||
parcel.scripts
|
.sort((a, b) => Number(a.id) - Number(b.id))
|
||||||
.sort((a, b) => Number(a.id) - Number(b.id))
|
.forEach((s) => {
|
||||||
.forEach((s) => {
|
document.body.removeChild(document.body.appendChild(s));
|
||||||
document.body.removeChild(document.body.appendChild(s));
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import postman, { item } from "postman";
|
import postman, { item } from "postman";
|
||||||
import type { Parcel } from "postman";
|
|
||||||
import { formatNumber } from "~/lib/t";
|
import { formatNumber } from "~/lib/t";
|
||||||
|
|
||||||
(function () {
|
(async function () {
|
||||||
const docel = document.documentElement;
|
const docel = document.documentElement;
|
||||||
const main = docel.querySelector(".postman.main")!;
|
const main = docel.querySelector(".postman.main")!;
|
||||||
const css = docel.querySelector(".postman.css")!;
|
const css = docel.querySelector(".postman.css")!;
|
||||||
|
@ -22,7 +21,7 @@ import { formatNumber } from "~/lib/t";
|
||||||
return f;
|
return f;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const delivery = postman(
|
const parcel = await postman(
|
||||||
item.script(`/js/main/vendor.js?v=${rev}`, { id: "0" }),
|
item.script(`/js/main/vendor.js?v=${rev}`, { id: "0" }),
|
||||||
item.script(`/js/main/surah-stream.js?v=${rev}`, { id: "1" }),
|
item.script(`/js/main/surah-stream.js?v=${rev}`, { id: "1" }),
|
||||||
...fonts,
|
...fonts,
|
||||||
|
@ -38,15 +37,13 @@ import { formatNumber } from "~/lib/t";
|
||||||
num.innerText = formatNumber(docel.lang, Number(percent.toFixed(0)));
|
num.innerText = formatNumber(docel.lang, Number(percent.toFixed(0)));
|
||||||
}),
|
}),
|
||||||
).deliver();
|
).deliver();
|
||||||
delivery.then((parcel: Parcel) => {
|
[main, css].forEach((el) => el.remove());
|
||||||
[main, css].forEach((el) => el.remove());
|
parcel.fonts.forEach((f) => document.fonts.add(f));
|
||||||
parcel.fonts.forEach((f) => document.fonts.add(f));
|
parcel.css.forEach((s) => document.head.appendChild(s));
|
||||||
parcel.css.forEach((s) => document.head.appendChild(s));
|
parcel.json.forEach((o) => document.body.appendChild(o));
|
||||||
parcel.json.forEach((o) => document.body.appendChild(o));
|
parcel.scripts
|
||||||
parcel.scripts
|
.sort((a, b) => Number(a.id) - Number(b.id))
|
||||||
.sort((a, b) => Number(a.id) - Number(b.id))
|
.forEach((s) => {
|
||||||
.forEach((s) => {
|
document.body.removeChild(document.body.appendChild(s));
|
||||||
document.body.removeChild(document.body.appendChild(s));
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in a new issue