1
- import { Component } from 'mo/react' ;
1
+ import { singleton , container } from 'tsyringe' ;
2
+ import { isEmpty } from 'loadsh' ;
2
3
3
- import { ITab } from 'mo/components/tabs ' ;
4
+ import { Component } from 'mo/react ' ;
4
5
import { emit } from 'mo/common/event' ;
5
- import { singleton , container } from 'tsyringe ' ;
6
+ import { ITab } from 'mo/components/tabs ' ;
6
7
import {
7
8
EditorEvent ,
8
9
EditorModel ,
@@ -35,12 +36,10 @@ export class EditorService
35
36
36
37
@emit ( EditorEvent . OnSelectTab )
37
38
onSelectTab ( callback : ( tabKey : string ) => void ) {
38
- this . subscribe ( EditorEvent . OnSelectTab , ( args ) => {
39
+ this . subscribe ( EditorEvent . OnSelectTab , ( targetKey : string , groupId ?: number ) => {
39
40
let group ;
40
41
let { groups } = this . state ;
41
- const groupId = args ?. [ 1 ] ;
42
- const targetKey = args ?. [ 0 ] ;
43
- if ( ! groupId ) return ;
42
+ if ( groupId === undefined ) return ;
44
43
group = groups ?. find ( ( group : IEditorGroup ) => group . id === groupId ) ;
45
44
group . activeTab = { ...group . activeTab , key : targetKey } ;
46
45
callback ?.( targetKey ) ;
@@ -66,26 +65,23 @@ export class EditorService
66
65
67
66
@emit ( EditorEvent . OnMoveTab )
68
67
public onMoveTab ( callback : ( data ) => void ) {
69
- this . subscribe ( EditorEvent . OnMoveTab , ( args ) => {
68
+ this . subscribe ( EditorEvent . OnMoveTab , ( tabs : ITab [ ] , groupId ?: number ) => {
70
69
let { groups } = this . state ;
71
70
let group ;
72
- if ( ! args ?. [ 1 ] ) return ;
73
- const groupId = args ?. [ 1 ] ;
71
+ if ( isEmpty ( groupId ) ) return ;
74
72
group = groups ?. find ( ( group : IEditorGroup ) => group . id === groupId ) ;
75
- group . tabs = args ?. [ 0 ] ;
76
- callback ?.( args ?. [ 0 ] ) ;
73
+ group . tabs = tabs ;
74
+ callback ?.( tabs ) ;
77
75
} ) ;
78
76
}
79
77
public closeAll ( ) { }
80
78
81
79
@emit ( EditorEvent . OnCloseTab )
82
80
public onCloseTab ( callback : ( data ) => void ) {
83
- this . subscribe ( EditorEvent . OnCloseTab , ( args ) => {
81
+ this . subscribe ( EditorEvent . OnCloseTab , ( targetKey : string , groupId ?: number ) => {
84
82
let group , lastIndex ;
85
83
let { groups } = this . state ;
86
- const groupId = args ?. [ 1 ] ;
87
- const targetKey = args ?. [ 0 ] ;
88
- if ( ! groupId ) return ;
84
+ if ( groupId === undefined ) return ;
89
85
group = groups ?. find ( ( group : IEditorGroup ) => group . id === groupId ) ;
90
86
let newActiveKey = group ?. activeTab ?. key ;
91
87
const groupTabs = group . tabs ;
0 commit comments