1- import { Editor as InnerEditor , globalContext } from '@alilc/lowcode-editor-core' ;
1+ import { Editor as InnerEditor , EventBus } from '@alilc/lowcode-editor-core' ;
22import { getLogger , isPublicEventName , isPluginEventName } from '@alilc/lowcode-utils' ;
3- import { editorSymbol } from '../symbols' ;
43import { IPublicApiEvent , IPublicTypeDisposable } from '@alilc/lowcode-types' ;
54
65const logger = getLogger ( { level : 'warn' , bizName : 'shell-event' } ) ;
@@ -9,10 +8,10 @@ type EventOptions = {
98 prefix : string ;
109} ;
1110
12- const innerEditorSymbol = Symbol ( 'editor ' ) ;
11+ const eventBusSymbol = Symbol ( 'eventBus ' ) ;
1312
1413export class Event implements IPublicApiEvent {
15- private readonly [ editorSymbol ] : InnerEditor ;
14+ private readonly [ eventBusSymbol ] : EventBus ;
1615 private readonly options : EventOptions ;
1716
1817 // TODO:
@@ -21,8 +20,8 @@ export class Event implements IPublicApiEvent {
2120 */
2221 readonly names = [ ] ;
2322
24- constructor ( editor : InnerEditor , options : EventOptions , public workspaceMode = false ) {
25- this [ editorSymbol ] = editor ;
23+ constructor ( eventBus : EventBus , options : EventOptions , public workspaceMode = false ) {
24+ this [ eventBusSymbol ] = eventBus ;
2625 this . options = options ;
2726 if ( ! this . options . prefix ) {
2827 logger . warn ( 'prefix is required while initializing Event' ) ;
@@ -36,7 +35,7 @@ export class Event implements IPublicApiEvent {
3635 */
3736 on ( event : string , listener : ( ...args : any [ ] ) => void ) : IPublicTypeDisposable {
3837 if ( isPluginEventName ( event ) || isPublicEventName ( event ) ) {
39- return this [ editorSymbol ] . eventBus . on ( event , listener ) ;
38+ return this [ eventBusSymbol ] . on ( event , listener ) ;
4039 } else {
4140 logger . warn ( `fail to monitor on event ${ event } , which is neither a engine public event nor a plugin event` ) ;
4241 return ( ) => { } ;
@@ -49,7 +48,7 @@ export class Event implements IPublicApiEvent {
4948 * @param listener 事件回调
5049 */
5150 off ( event : string , listener : ( ...args : any [ ] ) => void ) {
52- this [ editorSymbol ] . eventBus . off ( event , listener ) ;
51+ this [ eventBusSymbol ] . off ( event , listener ) ;
5352 }
5453
5554 /**
@@ -63,7 +62,7 @@ export class Event implements IPublicApiEvent {
6362 logger . warn ( 'Event#emit has been forbidden while prefix is not specified' ) ;
6463 return ;
6564 }
66- this [ editorSymbol ] . eventBus . emit ( `${ this . options . prefix } :${ event } ` , ...args ) ;
65+ this [ eventBusSymbol ] . emit ( `${ this . options . prefix } :${ event } ` , ...args ) ;
6766 }
6867
6968 /**
@@ -72,10 +71,10 @@ export class Event implements IPublicApiEvent {
7271 * @param args
7372 */
7473 __internalEmit__ ( event : string , ...args : unknown [ ] ) {
75- this [ editorSymbol ] . emit ( event , ...args ) ;
74+ this [ eventBusSymbol ] . emit ( event , ...args ) ;
7675 }
7776}
7877
7978export function getEvent ( editor : InnerEditor , options : any = { prefix : 'common' } ) {
80- return new Event ( editor , options ) ;
79+ return new Event ( editor . eventBus , options ) ;
8180}
0 commit comments