mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-06-25 11:49:16 +08:00
refactor(data-source): 注册base/http数据源的代码有副作用
This commit is contained in:
parent
50b74d10e6
commit
9252822c58
@ -21,8 +21,8 @@ import EventEmitter from 'events';
|
||||
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
|
||||
import type { DataSourceSchema, default as TMagicApp, DisplayCond, Id, MNode, NODE_CONDS_KEY } from '@tmagic/core';
|
||||
import { compiledNode } from '@tmagic/core';
|
||||
import type { DataSourceSchema, default as TMagicApp, DisplayCond, Id, MNode } from '@tmagic/core';
|
||||
import { compiledNode, NODE_CONDS_KEY } from '@tmagic/core';
|
||||
|
||||
import { SimpleObservedData } from './observed-data/SimpleObservedData';
|
||||
import { DataSource, HttpDataSource } from './data-sources';
|
||||
@ -31,7 +31,10 @@ import type { ChangeEvent, DataSourceManagerData, DataSourceManagerOptions, Obse
|
||||
import { compiledNodeField, compliedConditions, compliedIteratorItem, createIteratorContentData } from './utils';
|
||||
|
||||
class DataSourceManager extends EventEmitter {
|
||||
private static dataSourceClassMap = new Map<string, typeof DataSource>();
|
||||
private static dataSourceClassMap = new Map<string, any>([
|
||||
['base', DataSource],
|
||||
['http', HttpDataSource],
|
||||
]);
|
||||
private static ObservedDataClass: ObservedDataClass = SimpleObservedData;
|
||||
private static waitInitSchemaList = new Map<DataSourceManager, Record<string, DataSourceSchema[]>>();
|
||||
|
||||
@ -52,6 +55,12 @@ class DataSourceManager extends EventEmitter {
|
||||
return DataSourceManager.dataSourceClassMap.get(type);
|
||||
}
|
||||
|
||||
public static clearDataSourceClass() {
|
||||
DataSourceManager.dataSourceClassMap.clear();
|
||||
DataSourceManager.dataSourceClassMap.set('base', DataSource);
|
||||
DataSourceManager.dataSourceClassMap.set('http', HttpDataSource);
|
||||
}
|
||||
|
||||
public static registerObservedData(ObservedDataClass: ObservedDataClass) {
|
||||
DataSourceManager.ObservedDataClass = ObservedDataClass;
|
||||
}
|
||||
@ -320,7 +329,4 @@ class DataSourceManager extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
DataSourceManager.register('http', HttpDataSource as any);
|
||||
DataSourceManager.register('base', DataSource as any);
|
||||
|
||||
export default DataSourceManager;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { afterAll, describe, expect, test } from 'vitest';
|
||||
|
||||
import TMagicApp, { NodeType } from '@tmagic/core';
|
||||
|
||||
@ -28,6 +28,10 @@ const app = new TMagicApp({
|
||||
},
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
DataSourceManager.clearDataSourceClass();
|
||||
});
|
||||
|
||||
describe('DataSourceManager', () => {
|
||||
const dsm = new DataSourceManager({
|
||||
app,
|
||||
|
@ -47,5 +47,7 @@ describe('createDataSourceManager', () => {
|
||||
test('instance', () => {
|
||||
const manager = createDataSourceManager(new TMagicApp({ config: dsl }));
|
||||
expect(manager).toBeInstanceOf(DataSourceManager);
|
||||
|
||||
DataSourceManager.clearDataSourceClass();
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user