mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-04 14:59:48 +08:00
fix(data-source): 兼容Promise.allSettled
This commit is contained in:
parent
5873842260
commit
7ee7f53938
@ -74,21 +74,32 @@ class DataSourceManager extends EventEmitter {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const dataSourceList = Array.from(this.dataSourceMap);
|
const dataSourceList = Array.from(this.dataSourceMap);
|
||||||
Promise.allSettled<Record<string, any>>(dataSourceList.map(([, ds]) => this.init(ds))).then((values) => {
|
|
||||||
const data: DataSourceManagerData = {};
|
|
||||||
const errors: Record<string, Error> = {};
|
|
||||||
|
|
||||||
values.forEach((value, index) => {
|
if (typeof Promise.allSettled === 'function') {
|
||||||
const dsId = dataSourceList[index][0];
|
Promise.allSettled<Record<string, any>>(dataSourceList.map(([, ds]) => this.init(ds))).then((values) => {
|
||||||
if (value.status === 'fulfilled') {
|
const data: DataSourceManagerData = {};
|
||||||
data[dsId] = this.data[dsId];
|
const errors: Record<string, Error> = {};
|
||||||
} else if (value.status === 'rejected') {
|
|
||||||
errors[dsId] = value.reason;
|
values.forEach((value, index) => {
|
||||||
}
|
const dsId = dataSourceList[index][0];
|
||||||
|
if (value.status === 'fulfilled') {
|
||||||
|
data[dsId] = this.data[dsId];
|
||||||
|
} else if (value.status === 'rejected') {
|
||||||
|
errors[dsId] = value.reason;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.emit('init', data, errors);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
this.emit('init', data, errors);
|
Promise.all<Record<string, any>>(dataSourceList.map(([, ds]) => this.init(ds)))
|
||||||
});
|
.then(() => {
|
||||||
|
this.emit('init', this.data);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.emit('init', this.data);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async init(ds: DataSource) {
|
public async init(ds: DataSource) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user