Port 216dbaedaf
to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
main
parent
d86cb4cab8
commit
cc93cd5d6c
@ -1,8 +1,10 @@
|
||||
import 'packs/public-path';
|
||||
import loadPolyfills from 'flavours/glitch/util/load_polyfills';
|
||||
|
||||
loadPolyfills().then(() => {
|
||||
require('flavours/glitch/util/main').default();
|
||||
loadPolyfills().then(async () => {
|
||||
const { default: main } = import('flavours/glitch/util/main');
|
||||
|
||||
return main();
|
||||
}).catch(e => {
|
||||
console.error(e);
|
||||
});
|
||||
|
@ -1,7 +1,32 @@
|
||||
export default function ready(loaded) {
|
||||
if (['interactive', 'complete'].includes(document.readyState)) {
|
||||
loaded();
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', loaded);
|
||||
}
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* @param {(() => void) | (() => Promise<void>)} callback
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export default function ready(callback) {
|
||||
return new Promise((resolve, reject) => {
|
||||
function loaded() {
|
||||
let result;
|
||||
try {
|
||||
result = callback();
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof result?.then === 'function') {
|
||||
result.then(resolve).catch(reject);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
|
||||
if (['interactive', 'complete'].includes(document.readyState)) {
|
||||
loaded();
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', loaded);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in new issue