fix(plugins): Fix timing issues with loadScript
This commit is contained in:
parent
b8eadd6d61
commit
c09b54924e
@ -9,18 +9,21 @@ export class OHIFPlugin {
|
|||||||
// load an individual script URL
|
// load an individual script URL
|
||||||
static loadScript(scriptURL, type = "text/javascript") {
|
static loadScript(scriptURL, type = "text/javascript") {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
const head = document.getElementsByTagName("head")[0];
|
||||||
const script = document.createElement("script");
|
const script = document.createElement("script");
|
||||||
|
|
||||||
script.onload = resolve;
|
script.onload = () => {
|
||||||
|
head.removeChild(script);
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
|
||||||
script.onerror = reject;
|
script.onerror = reject;
|
||||||
|
|
||||||
script.src = scriptURL;
|
script.src = scriptURL;
|
||||||
script.type = type;
|
script.type = type;
|
||||||
script.async = false;
|
script.async = false;
|
||||||
|
|
||||||
const head = document.getElementsByTagName("head")[0];
|
|
||||||
head.appendChild(script);
|
head.appendChild(script);
|
||||||
head.removeChild(script);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,11 +51,16 @@ export class OHIFPlugin {
|
|||||||
|
|
||||||
const type = plugin.module === true ? 'module' : 'text/javascript'
|
const type = plugin.module === true ? 'module' : 'text/javascript'
|
||||||
|
|
||||||
this.loadScript(scriptURL, type).then(function() {
|
console.warn(`Calling loadScript for ${plugin.name}`);
|
||||||
|
console.time(`loadScript ${plugin.name}`);
|
||||||
|
this.loadScript(scriptURL, type).then((script) => {
|
||||||
|
console.timeEnd(`loadScript ${plugin.name}`);
|
||||||
const entryPointFunction = OHIF.plugins.entryPoints[plugin.name];
|
const entryPointFunction = OHIF.plugins.entryPoints[plugin.name];
|
||||||
|
|
||||||
if (entryPointFunction) {
|
if (entryPointFunction) {
|
||||||
entryPointFunction();
|
entryPointFunction();
|
||||||
|
} else {
|
||||||
|
throw new Error(`No entry point found for ${plugin.name}`);
|
||||||
}
|
}
|
||||||
}, error => {
|
}, error => {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user