mirror of
				https://github.com/Tencent/tmagic-editor.git
				synced 2025-11-04 18:52:18 +08:00 
			
		
		
		
	fix(core): 修复执行代码块的顺序问题
This commit is contained in:
		
							parent
							
								
									09c9af8454
								
							
						
					
					
						commit
						c3b502254b
					
				@ -40,7 +40,9 @@
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "@types/events": "^3.0.0",
 | 
			
		||||
    "@types/lodash-es": "^4.17.4",
 | 
			
		||||
    "@types/node": "^15.12.4",
 | 
			
		||||
    "lodash-es": "^4.17.21",
 | 
			
		||||
    "rimraf": "^3.0.2",
 | 
			
		||||
    "typescript": "^4.7.4",
 | 
			
		||||
    "vite": "^3.1.3"
 | 
			
		||||
 | 
			
		||||
@ -18,6 +18,8 @@
 | 
			
		||||
 | 
			
		||||
import { EventEmitter } from 'events';
 | 
			
		||||
 | 
			
		||||
import { isEmpty } from 'lodash-es';
 | 
			
		||||
 | 
			
		||||
import type { EventItemConfig, MComponent, MContainer, MPage } from '@tmagic/schema';
 | 
			
		||||
 | 
			
		||||
import type App from './App';
 | 
			
		||||
@ -66,15 +68,7 @@ class Node extends EventEmitter {
 | 
			
		||||
  private listenLifeSafe() {
 | 
			
		||||
    this.once('created', async (instance: any) => {
 | 
			
		||||
      this.instance = instance;
 | 
			
		||||
      if (Array.isArray(this.data.created) && this.app?.codeDsl) {
 | 
			
		||||
        await Promise.all(
 | 
			
		||||
          this.data.created.map(async (codeId) => {
 | 
			
		||||
            if (this.app.codeDsl[codeId] && typeof this.app?.codeDsl[codeId]?.content === 'function') {
 | 
			
		||||
              await this.app.codeDsl[codeId].content(this);
 | 
			
		||||
            }
 | 
			
		||||
          }),
 | 
			
		||||
        );
 | 
			
		||||
      }
 | 
			
		||||
      await this.runCodeBlock('created');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    this.once('mounted', async (instance: any) => {
 | 
			
		||||
@ -86,17 +80,18 @@ class Node extends EventEmitter {
 | 
			
		||||
        this.app.eventHandler(eventConfig.eventConfig, eventConfig.fromCpt, eventConfig.args);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (Array.isArray(this.data.mounted)) {
 | 
			
		||||
        await Promise.all(
 | 
			
		||||
          this.data.mounted.map(async (codeId) => {
 | 
			
		||||
            if (this.app?.codeDsl[codeId] && typeof this.app?.codeDsl[codeId]?.content === 'function') {
 | 
			
		||||
              await this.app.codeDsl[codeId].content(this);
 | 
			
		||||
            }
 | 
			
		||||
          }),
 | 
			
		||||
        );
 | 
			
		||||
      }
 | 
			
		||||
      await this.runCodeBlock('mounted');
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private async runCodeBlock(hook: string) {
 | 
			
		||||
    if (!Array.isArray(this.data[hook]) || isEmpty(this.app?.codeDsl)) return;
 | 
			
		||||
    for (const codeId of this.data[hook]) {
 | 
			
		||||
      if (this.app?.codeDsl[codeId] && typeof this.app?.codeDsl[codeId]?.content === 'function') {
 | 
			
		||||
        await this.app.codeDsl[codeId].content(this);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default Node;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										5
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										5
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							@ -136,8 +136,10 @@ importers:
 | 
			
		||||
    specifiers:
 | 
			
		||||
      '@tmagic/schema': 1.1.6
 | 
			
		||||
      '@types/events': ^3.0.0
 | 
			
		||||
      '@types/lodash-es': ^4.17.4
 | 
			
		||||
      '@types/node': ^15.12.4
 | 
			
		||||
      events: ^3.3.0
 | 
			
		||||
      lodash-es: ^4.17.21
 | 
			
		||||
      rimraf: ^3.0.2
 | 
			
		||||
      typescript: ^4.7.4
 | 
			
		||||
      vite: ^3.1.3
 | 
			
		||||
@ -146,7 +148,9 @@ importers:
 | 
			
		||||
      events: 3.3.0
 | 
			
		||||
    devDependencies:
 | 
			
		||||
      '@types/events': 3.0.0
 | 
			
		||||
      '@types/lodash-es': 4.17.6
 | 
			
		||||
      '@types/node': 15.14.9
 | 
			
		||||
      lodash-es: 4.17.21
 | 
			
		||||
      rimraf: 3.0.2
 | 
			
		||||
      typescript: 4.7.4
 | 
			
		||||
      vite: 3.1.3
 | 
			
		||||
@ -5559,7 +5563,6 @@ packages:
 | 
			
		||||
 | 
			
		||||
  /lodash-es/4.17.21:
 | 
			
		||||
    resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==}
 | 
			
		||||
    dev: false
 | 
			
		||||
 | 
			
		||||
  /lodash-unified/1.0.2_3ib2ivapxullxkx3xftsimdk7u:
 | 
			
		||||
    resolution: {integrity: sha512-OGbEy+1P+UT26CYi4opY4gebD8cWRDxAT6MAObIVQMiqYdxZr1g3QHWCToVsm31x2NkLS4K3+MC2qInaRMa39g==}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user