[IMP] utils: whenReady now returns a Promise

Closes #160
This commit is contained in:
Aaron Bohy
2019-06-11 13:36:59 +02:00
committed by Géry Debongnie
parent 22e48e3be0
commit c2ab9774fb
3 changed files with 35 additions and 24 deletions
+7 -5
View File
@@ -11,11 +11,13 @@
*/
export function whenReady(fn) {
if (document.readyState !== "loading") {
fn();
} else {
document.addEventListener("DOMContentLoaded", fn, false);
}
return new Promise(function(resolve) {
if (document.readyState !== "loading") {
resolve();
} else {
document.addEventListener("DOMContentLoaded", resolve, false);
}
}).then(fn || function () {});
}
const loadedScripts: { [key: string]: Promise<void> } = {};