Browse Source

Merge pull request #252071 in DEC/fineui from master to feature/x

* commit 'e041bbdccf72b5bacbf47d98670b393cd1d0ce4c':
  update
  无JIRA 更新异步加载方法
research/test
superman 1 year ago
parent
commit
a2d74a631c
  1. 19
      packages/fineui/src/core/platform/web/load.js
  2. 2
      packages/fineui/typescript/core/base.ts
  3. 2
      packages/fineui/typescript/core/platform/web/load.ts

19
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<boolean>|Promise<unknown>}
*/
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]);
}
/**

2
packages/fineui/typescript/core/base.ts

@ -266,7 +266,7 @@ export declare function isNull(obj: any): obj is (undefined | null);
export declare function isEmptyArray<T, U>(arr: T[] | U): arr is T[] & { length: 0 };
export declare function isNotEmptyArray<T, U>(arr: T[] | U): arr is [T, ...T[]];
export declare function isNotEmptyArray<T>(arr: T[]): arr is NonNullable<T>[];
export declare function isEmptyObject(obj: any): boolean;

2
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<any>

Loading…
Cancel
Save