From 4f0a423f240c9c3b07126ed783dc0c24ad70884b Mon Sep 17 00:00:00 2001 From: dailer Date: Thu, 26 Oct 2023 15:16:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=97=A0JIRA=20=E6=9B=B4=E6=96=B0=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E5=8A=A0=E8=BD=BD=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/fineui/src/core/platform/web/load.js | 19 ++++++++++++++----- packages/fineui/typescript/core/base.ts | 2 +- .../typescript/core/platform/web/load.ts | 2 ++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/fineui/src/core/platform/web/load.js b/packages/fineui/src/core/platform/web/load.js index 6dd203ea1..8a43934dd 100644 --- a/packages/fineui/src/core/platform/web/load.js +++ b/packages/fineui/src/core/platform/web/load.js @@ -81,25 +81,34 @@ export function syncLoadScript(uri) { return false; } + +const promises = {}; + /** * 默认的异步加载javascript方法 * @param uri * @returns {Promise|Promise} */ export function loadScript(uri) { - if (_LOADED[uri]) { - return Promise.resolve(true); + if (promises[uri]) { + return Promise.all(promises[uri]); } - return new Promise(resolve => { + + const promise = new Promise(resolve => { const script = document.createElement("script"); script.type = "application/javascript"; - script.src = uri; script.onload = function() { + _LOADED[uri] = true; resolve(true); }; + script.src = uri; document.head.appendChild(script); - _LOADED[uri] = true; }); + + promises[uri] ??= []; + promises[uri].push(promise); + + return Promise.all(promises[uri]); } /** diff --git a/packages/fineui/typescript/core/base.ts b/packages/fineui/typescript/core/base.ts index abdd7ba80..5b4a86af3 100644 --- a/packages/fineui/typescript/core/base.ts +++ b/packages/fineui/typescript/core/base.ts @@ -266,7 +266,7 @@ export declare function isNull(obj: any): obj is (undefined | null); export declare function isEmptyArray(arr: T[] | U): arr is T[] & { length: 0 }; -export declare function isNotEmptyArray(arr: T[] | U): arr is [T, ...T[]]; +export declare function isNotEmptyArray(arr: T[]): arr is NonNullable[]; export declare function isEmptyObject(obj: any): boolean; diff --git a/packages/fineui/typescript/core/platform/web/load.ts b/packages/fineui/typescript/core/platform/web/load.ts index 144150ff5..cef294db8 100644 --- a/packages/fineui/typescript/core/platform/web/load.ts +++ b/packages/fineui/typescript/core/platform/web/load.ts @@ -1 +1,3 @@ export declare function $import(src: string, ext?: string, must?: boolean): void + +export declare function loadResource(opt: { src: string, extension?: string, async?: boolean }): Promise From d7b26c22e1146d796927231570cbe0e1c818f0a6 Mon Sep 17 00:00:00 2001 From: dailer Date: Mon, 30 Oct 2023 09:52:47 +0800 Subject: [PATCH 2/2] update --- packages/fineui/src/core/platform/web/load.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fineui/src/core/platform/web/load.js b/packages/fineui/src/core/platform/web/load.js index 8a43934dd..d010bdb54 100644 --- a/packages/fineui/src/core/platform/web/load.js +++ b/packages/fineui/src/core/platform/web/load.js @@ -105,7 +105,7 @@ export function loadScript(uri) { document.head.appendChild(script); }); - promises[uri] ??= []; + promises[uri] = []; promises[uri].push(promise); return Promise.all(promises[uri]);