mirror of
				https://github.com/Tencent/tmagic-editor.git
				synced 2025-11-04 18:52:18 +08:00 
			
		
		
		
	fix(core): deep-state-observer update 的data与初始化时相同,导致get data为空
This commit is contained in:
		
							parent
							
								
									e8461f91e6
								
							
						
					
					
						commit
						701a9d6f30
					
				@ -1,8 +1,9 @@
 | 
			
		||||
import { describe, expect, test } from 'vitest';
 | 
			
		||||
 | 
			
		||||
import { MApp, NodeType, TMagicIteratorContainer } from '@tmagic/schema';
 | 
			
		||||
import { MApp, NodeType } from '@tmagic/schema';
 | 
			
		||||
 | 
			
		||||
import App from '../src/App';
 | 
			
		||||
import TMagicIteratorContainer from '../src/IteratorContainer';
 | 
			
		||||
 | 
			
		||||
const createAppDsl = (pageLength: number, nodeLength = 0) => {
 | 
			
		||||
  const dsl: MApp = {
 | 
			
		||||
 | 
			
		||||
@ -177,7 +177,7 @@ class DataSourceManager extends EventEmitter {
 | 
			
		||||
 | 
			
		||||
      this.removeDataSource(schema.id);
 | 
			
		||||
 | 
			
		||||
      this.addDataSource(schema);
 | 
			
		||||
      this.addDataSource(cloneDeep(schema));
 | 
			
		||||
      const newDs = this.get(schema.id);
 | 
			
		||||
      if (newDs) {
 | 
			
		||||
        this.init(newDs);
 | 
			
		||||
 | 
			
		||||
@ -62,13 +62,15 @@ export default class DataSource<T extends DataSourceSchema = DataSourceSchema> e
 | 
			
		||||
    // eslint-disable-next-line @typescript-eslint/naming-convention
 | 
			
		||||
    const ObservedDataClass = options.ObservedDataClass || SimpleObservedData;
 | 
			
		||||
    if (this.app.platform === 'editor') {
 | 
			
		||||
      const mocks = cloneDeep(options.schema.mocks || []);
 | 
			
		||||
      // 编辑器中有mock使用mock,没有使用默认值
 | 
			
		||||
      this.mockData = options.schema.mocks?.find((mock) => mock.useInEditor)?.data || this.getDefaultData();
 | 
			
		||||
      this.mockData = mocks.find((mock) => mock.useInEditor)?.data || this.getDefaultData();
 | 
			
		||||
      data = cloneDeep(this.mockData);
 | 
			
		||||
    } else if (typeof options.useMock === 'boolean' && options.useMock) {
 | 
			
		||||
      const mocks = cloneDeep(options.schema.mocks || []);
 | 
			
		||||
      // 设置了使用mock就使用mock数据
 | 
			
		||||
      this.mockData = options.schema.mocks?.find((mock) => mock.enable)?.data;
 | 
			
		||||
      data = this.mockData || this.getDefaultData();
 | 
			
		||||
      this.mockData = mocks.find((mock) => mock.enable)?.data;
 | 
			
		||||
      data = cloneDeep(this.mockData) || this.getDefaultData();
 | 
			
		||||
    } else if (!options.initialData) {
 | 
			
		||||
      data = this.getDefaultData();
 | 
			
		||||
    } else {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user