mirror of
				https://github.com/Tencent/tmagic-editor.git
				synced 2025-11-04 10:49:51 +08:00 
			
		
		
		
	feat(core): 支持统一设置node.store的初始值
This commit is contained in:
		
							parent
							
								
									d628ffad26
								
							
						
					
					
						commit
						abe27db47a
					
				@ -59,6 +59,7 @@ export interface AppOptionsConfig {
 | 
			
		||||
  request?: RequestFunction;
 | 
			
		||||
  DataSourceObservedData?: ObservedDataClass;
 | 
			
		||||
  dataSourceManagerInitialData?: DataSourceManagerData;
 | 
			
		||||
  nodeStoreInitialData?: () => any;
 | 
			
		||||
  errorHandler?: ErrorHandler;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -85,6 +86,7 @@ class App extends EventEmitter {
 | 
			
		||||
  public transformStyle: (style: Record<string, any>) => Record<string, any>;
 | 
			
		||||
  public eventHelper?: EventHelper;
 | 
			
		||||
  public errorHandler?: ErrorHandler;
 | 
			
		||||
  public nodeStoreInitialData?: () => any;
 | 
			
		||||
 | 
			
		||||
  private flexible?: Flexible;
 | 
			
		||||
 | 
			
		||||
@ -103,6 +105,7 @@ class App extends EventEmitter {
 | 
			
		||||
    this.codeDsl = options.config?.codeBlocks;
 | 
			
		||||
    options.platform && (this.platform = options.platform);
 | 
			
		||||
    options.jsEngine && (this.jsEngine = options.jsEngine);
 | 
			
		||||
    options.nodeStoreInitialData && (this.nodeStoreInitialData = options.nodeStoreInitialData);
 | 
			
		||||
 | 
			
		||||
    if (options.pageFragmentContainerType) {
 | 
			
		||||
      const pageFragmentContainerType = Array.isArray(options.pageFragmentContainerType)
 | 
			
		||||
@ -336,6 +339,8 @@ class App extends EventEmitter {
 | 
			
		||||
    this.dataSourceManager = undefined;
 | 
			
		||||
    this.codeDsl = undefined;
 | 
			
		||||
    this.components.clear();
 | 
			
		||||
 | 
			
		||||
    this.nodeStoreInitialData = undefined;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -53,7 +53,7 @@ class Node extends EventEmitter {
 | 
			
		||||
  public page?: Page;
 | 
			
		||||
  public parent?: Node;
 | 
			
		||||
  public app: TMagicApp;
 | 
			
		||||
  public store = new Store();
 | 
			
		||||
  public store;
 | 
			
		||||
  public eventKeys = new Map<string, symbol>();
 | 
			
		||||
 | 
			
		||||
  private eventQueue: EventCache[] = [];
 | 
			
		||||
@ -61,6 +61,7 @@ class Node extends EventEmitter {
 | 
			
		||||
  constructor(options: NodeOptions) {
 | 
			
		||||
    super();
 | 
			
		||||
 | 
			
		||||
    this.store = new Store({ initialData: options.app.nodeStoreInitialData?.() || {} });
 | 
			
		||||
    this.page = options.page;
 | 
			
		||||
    this.parent = options.parent;
 | 
			
		||||
    this.app = options.app;
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,9 @@
 | 
			
		||||
export default class Store {
 | 
			
		||||
  private data: Record<string, any> = {};
 | 
			
		||||
  private data: any;
 | 
			
		||||
 | 
			
		||||
  constructor({ initialData = {} }: { initialData?: any } = {}) {
 | 
			
		||||
    this.data = initialData;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public set(key: string, value: any) {
 | 
			
		||||
    this.data[key] = value;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user