mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-19 21:06:06 +08:00
feat(data-source): 由于存在异步加载数据源,新增所有数据源加载完毕事件
This commit is contained in:
parent
1e396d4a8d
commit
a35789c0cf
@ -89,15 +89,15 @@ class DataSourceManager extends EventEmitter {
|
|||||||
|
|
||||||
if (initialData) {
|
if (initialData) {
|
||||||
this.initialData = initialData;
|
this.initialData = initialData;
|
||||||
this.data = initialData;
|
this.data = { ...initialData };
|
||||||
}
|
}
|
||||||
|
|
||||||
app.dsl?.dataSources?.forEach((config) => {
|
app.dsl?.dataSources?.forEach((config) => {
|
||||||
this.addDataSource(config);
|
this.addDataSource(config);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.on('registered-all', () => {
|
||||||
const dataSourceList = Array.from(this.dataSourceMap);
|
const dataSourceList = Array.from(this.dataSourceMap);
|
||||||
|
|
||||||
if (typeof Promise.allSettled === 'function') {
|
if (typeof Promise.allSettled === 'function') {
|
||||||
Promise.allSettled<Record<string, any>>(dataSourceList.map(([, ds]) => this.init(ds))).then((values) => {
|
Promise.allSettled<Record<string, any>>(dataSourceList.map(([, ds]) => this.init(ds))).then((values) => {
|
||||||
const data: DataSourceManagerData = {};
|
const data: DataSourceManagerData = {};
|
||||||
@ -128,6 +128,7 @@ class DataSourceManager extends EventEmitter {
|
|||||||
this.emit('init', this.data);
|
this.emit('init', this.data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async init(ds: DataSource) {
|
public async init(ds: DataSource) {
|
||||||
@ -202,6 +203,10 @@ class DataSourceManager extends EventEmitter {
|
|||||||
this.setData(ds, changeEvent);
|
this.setData(ds, changeEvent);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!this.app.dsl?.dataSources || this.dataSourceMap.size === this.app.dsl.dataSources.length) {
|
||||||
|
this.emit('registered-all');
|
||||||
|
}
|
||||||
|
|
||||||
return ds;
|
return ds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,20 +226,22 @@ class DataSourceManager extends EventEmitter {
|
|||||||
* @param {DataSourceSchema[]} schemas 所有数据源配置
|
* @param {DataSourceSchema[]} schemas 所有数据源配置
|
||||||
*/
|
*/
|
||||||
public updateSchema(schemas: DataSourceSchema[]) {
|
public updateSchema(schemas: DataSourceSchema[]) {
|
||||||
schemas.forEach((schema) => {
|
for (const schema of schemas) {
|
||||||
const ds = this.get(schema.id);
|
const ds = this.get(schema.id);
|
||||||
if (!ds) {
|
if (!ds) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.removeDataSource(schema.id);
|
this.removeDataSource(schema.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const schema of schemas) {
|
||||||
this.addDataSource(cloneDeep(schema));
|
this.addDataSource(cloneDeep(schema));
|
||||||
const newDs = this.get(schema.id);
|
const newDs = this.get(schema.id);
|
||||||
if (newDs) {
|
if (newDs) {
|
||||||
this.init(newDs);
|
this.init(newDs);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user