From 3c66319b03c42305c66b0c6a87307fe747d9f90e Mon Sep 17 00:00:00 2001 From: roymondchen Date: Tue, 4 Mar 2025 17:05:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(data-source):=20=E5=A4=84=E7=90=86=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E5=8A=A8=E6=80=81=E5=8A=A0=E8=BD=BD=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=BA=90=E6=97=B6=EF=BC=8C=E5=88=9D=E5=A7=8B=E5=8C=96=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=BA=90=E8=BF=98=E6=9C=AA=E5=8A=A0=E8=BD=BD=E5=AE=8C?= =?UTF-8?q?=E6=AF=95=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/data-source/src/DataSourceManager.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/data-source/src/DataSourceManager.ts b/packages/data-source/src/DataSourceManager.ts index ac0dc7e4..e5f0aa8e 100644 --- a/packages/data-source/src/DataSourceManager.ts +++ b/packages/data-source/src/DataSourceManager.ts @@ -32,9 +32,15 @@ import { compiledNodeField, compliedConditions, compliedIteratorItem, createIter class DataSourceManager extends EventEmitter { private static dataSourceClassMap = new Map(); private static ObservedDataClass: ObservedDataClass = SimpleObservedData; + private static waitInitSchemaList = new Map(); public static register(type: string, dataSource: T) { DataSourceManager.dataSourceClassMap.set(type, dataSource); + DataSourceManager.waitInitSchemaList?.forEach((list, app) => { + for (let config = list.shift(); config; config = list.shift()) { + app.addDataSource(config); + } + }); } public static getDataSourceClass(type: string) { @@ -55,6 +61,8 @@ class DataSourceManager extends EventEmitter { constructor({ app, useMock, initialData }: DataSourceManagerOptions) { super(); + DataSourceManager.waitInitSchemaList.set(this, []); + this.app = app; this.useMock = useMock; @@ -133,7 +141,12 @@ class DataSourceManager extends EventEmitter { public async addDataSource(config?: DataSourceSchema) { if (!config) return; - const DataSourceClass = DataSourceManager.dataSourceClassMap.get(config.type) || DataSource; + const DataSourceClass = DataSourceManager.dataSourceClassMap.get(config.type); + + if (!DataSourceClass) { + DataSourceManager.waitInitSchemaList.get(this)?.push(config); + return; + } const ds = new DataSourceClass({ app: this.app, @@ -276,6 +289,7 @@ class DataSourceManager extends EventEmitter { ds.destroy(); }); this.dataSourceMap.clear(); + DataSourceManager.waitInitSchemaList.delete(this); } public onDataChange(id: string, path: string, callback: (newVal: any) => void) { @@ -288,5 +302,6 @@ class DataSourceManager extends EventEmitter { } DataSourceManager.register('http', HttpDataSource as any); +DataSourceManager.register('base', DataSource as any); export default DataSourceManager;