mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-19 12:14:27 +08:00
fix(data-source): 异步加载数据源时,初始化第一次编译时数据源可能未加载,需要优先设置数据源默认值
This commit is contained in:
parent
1444eb6ae7
commit
fc886715c7
@ -22,12 +22,18 @@ import EventEmitter from 'events';
|
|||||||
import { cloneDeep } from 'lodash-es';
|
import { cloneDeep } from 'lodash-es';
|
||||||
|
|
||||||
import type { DataSourceSchema, default as TMagicApp, DisplayCond, Id, MNode } from '@tmagic/core';
|
import type { DataSourceSchema, default as TMagicApp, DisplayCond, Id, MNode } from '@tmagic/core';
|
||||||
import { compiledNode, NODE_CONDS_KEY } from '@tmagic/core';
|
import { compiledNode, getDefaultValueFromFields, NODE_CONDS_KEY } from '@tmagic/core';
|
||||||
|
|
||||||
import { SimpleObservedData } from './observed-data/SimpleObservedData';
|
import { SimpleObservedData } from './observed-data/SimpleObservedData';
|
||||||
import { DataSource, HttpDataSource } from './data-sources';
|
import { DataSource, HttpDataSource } from './data-sources';
|
||||||
import { getDeps } from './depsCache';
|
import { getDeps } from './depsCache';
|
||||||
import type { ChangeEvent, DataSourceManagerData, DataSourceManagerOptions, ObservedDataClass } from './types';
|
import type {
|
||||||
|
ChangeEvent,
|
||||||
|
DataSourceManagerData,
|
||||||
|
DataSourceManagerOptions,
|
||||||
|
ObservedDataClass,
|
||||||
|
SchemaListMap,
|
||||||
|
} from './types';
|
||||||
import { compiledNodeField, compliedConditions, compliedIteratorItem, createIteratorContentData } from './utils';
|
import { compiledNodeField, compliedConditions, compliedIteratorItem, createIteratorContentData } from './utils';
|
||||||
|
|
||||||
class DataSourceManager extends EventEmitter {
|
class DataSourceManager extends EventEmitter {
|
||||||
@ -36,7 +42,7 @@ class DataSourceManager extends EventEmitter {
|
|||||||
['http', HttpDataSource],
|
['http', HttpDataSource],
|
||||||
]);
|
]);
|
||||||
private static ObservedDataClass: ObservedDataClass = SimpleObservedData;
|
private static ObservedDataClass: ObservedDataClass = SimpleObservedData;
|
||||||
private static waitInitSchemaList = new Map<DataSourceManager, Record<string, DataSourceSchema[]>>();
|
private static waitInitSchemaList = new Map<DataSourceManager, SchemaListMap>();
|
||||||
|
|
||||||
public static register<T extends typeof DataSource = typeof DataSource>(type: string, dataSource: T) {
|
public static register<T extends typeof DataSource = typeof DataSource>(type: string, dataSource: T) {
|
||||||
DataSourceManager.dataSourceClassMap.set(type, dataSource);
|
DataSourceManager.dataSourceClassMap.set(type, dataSource);
|
||||||
@ -171,6 +177,9 @@ class DataSourceManager extends EventEmitter {
|
|||||||
listMap[config.type] = [config];
|
listMap[config.type] = [config];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保证初始化时的第一次编译有值
|
||||||
|
this.data[config.id] = getDefaultValueFromFields(config.fields);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,3 +65,7 @@ export interface ChangeEvent {
|
|||||||
export type AsyncDataSourceResolveResult<T = typeof DataSource> = {
|
export type AsyncDataSourceResolveResult<T = typeof DataSource> = {
|
||||||
default: T;
|
default: T;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export interface SchemaListMap {
|
||||||
|
[key: string]: DataSourceSchema[];
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user