Skip to content

Commit d6494f6

Browse files
Merge pull request #393 from wuchenguang1998/main
fix: 修复字体列表重复请求问题
2 parents bd34a13 + 6e950ae commit d6494f6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/core/plugin/FontPlugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ interface FontSource {
3030
class FontPlugin {
3131
public canvas: fabric.Canvas;
3232
public editor: IEditor;
33+
private tempPromise: Promise<FontSource[]> | null;
3334
static pluginName = 'FontPlugin';
3435
static apis = ['getFontList', 'loadFont', 'getFontJson', 'downFontByJSON'];
3536
repoSrc: string;
@@ -39,6 +40,7 @@ class FontPlugin {
3940
this.editor = editor;
4041
this.repoSrc = config.repoSrc;
4142
this.cacheList = [];
43+
this.tempPromise = null;
4244
}
4345

4446
hookImportBefore(json: string) {
@@ -49,7 +51,8 @@ class FontPlugin {
4951
if (this.cacheList.length) {
5052
return Promise.resolve(this.cacheList);
5153
}
52-
return axios
54+
if (this.tempPromise) return this.tempPromise;
55+
this.tempPromise = axios
5356
.get(`${this.repoSrc}/api/fonts?populate=*&pagination[pageSize]=100`)
5457
.then((res) => {
5558
const list = res.data.data.map((item: any) => {
@@ -64,6 +67,7 @@ class FontPlugin {
6467
this.createFontCSS(list);
6568
return list;
6669
});
70+
return this.tempPromise;
6771
}
6872

6973
downFontByJSON(str: string) {

0 commit comments

Comments
 (0)