mirror of
				https://github.com/Tencent/tmagic-editor.git
				synced 2025-11-04 18:52:18 +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 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 { DataSource, HttpDataSource } from './data-sources';
 | 
			
		||||
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';
 | 
			
		||||
 | 
			
		||||
class DataSourceManager extends EventEmitter {
 | 
			
		||||
@ -36,7 +42,7 @@ class DataSourceManager extends EventEmitter {
 | 
			
		||||
    ['http', HttpDataSource],
 | 
			
		||||
  ]);
 | 
			
		||||
  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) {
 | 
			
		||||
    DataSourceManager.dataSourceClassMap.set(type, dataSource);
 | 
			
		||||
@ -171,6 +177,9 @@ class DataSourceManager extends EventEmitter {
 | 
			
		||||
        listMap[config.type] = [config];
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      // 保证初始化时的第一次编译有值
 | 
			
		||||
      this.data[config.id] = getDefaultValueFromFields(config.fields);
 | 
			
		||||
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -65,3 +65,7 @@ export interface ChangeEvent {
 | 
			
		||||
export type AsyncDataSourceResolveResult<T = typeof DataSource> = {
 | 
			
		||||
  default: T;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export interface SchemaListMap {
 | 
			
		||||
  [key: string]: DataSourceSchema[];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user