@studiometa/js-toolkit
Version:
A set of useful little bits of JavaScript to boost your project! 🚀
51 lines (50 loc) • 1.21 kB
JavaScript
import { features } from "../Base/features.js";
import { isBoolean, isObject, isString } from "../utils/index.js";
function createApp(App, options = {}) {
let app;
const {
root = document.body,
breakpoints = null,
blocking = null,
prefix = null,
attributes = null
} = options instanceof HTMLElement ? { root: options } : options;
if (isObject(breakpoints)) {
features.set("breakpoints", breakpoints);
}
if (isBoolean(blocking)) {
features.set("blocking", blocking);
}
if (isString(prefix)) {
features.set("prefix", prefix);
}
if (isObject(attributes)) {
features.set("attributes", attributes);
}
async function init() {
app = new App(root);
await app.$mount();
return app;
}
let p;
if (features.get("blocking")) {
p = init();
} else {
p = new Promise((resolve) => {
if (document.readyState === "complete") {
resolve(init());
} else {
document.addEventListener("readystatechange", () => {
if (document.readyState === "complete") {
resolve(init());
}
});
}
});
}
return () => p;
}
export {
createApp
};
//# sourceMappingURL=createApp.js.map