Skip to content

Commit dd2577d

Browse files
committed
feat: resovle #37
1 parent 3597665 commit dd2577d

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

src/model/workbench/editor.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,39 @@ export enum EditorEvent {
1010
OpenTab = 'editor.openTab',
1111
OnSelectTab = 'editor.selectTab',
1212
}
13-
export interface IEditor {
13+
export interface IEditor<T> {
1414
current: IEditorGroup | undefined;
1515
groups: IEditorGroup[];
1616
closeAll?: () => void;
1717
onCloseTab?: (tabKey?: string, group?: number) => void;
1818
render?: () => React.ReactNode;
19-
onMoveTab?: (tabs: ITab[], group?: number) => void;
19+
onMoveTab?: (tabs: ITab<T>[], group?: number) => void;
2020
onSelectTab?: (tabKey: string, group?: number) => void;
2121
}
2222

23-
export interface IEditorGroup<E = any> {
23+
export interface IEditorGroup<E = any, T = any> {
2424
id: number;
25-
activeTab: ITab;
26-
tabs: ITab[];
25+
activeTab: ITab<T>;
26+
tabs: ITab<T>[];
2727
breadcrumb: any[];
2828
actions: any[];
2929
menu: any[];
3030
editorInstance?: E | null;
3131
}
3232

33-
export class EditorGroupModel implements IEditorGroup {
33+
export class EditorGroupModel<T> implements IEditorGroup<T> {
3434
id: number;
35-
activeTab: ITab;
36-
tabs: ITab[];
35+
activeTab: ITab<T>;
36+
tabs: ITab<T>[];
3737
breadcrumb: any[];
3838
actions: any[];
3939
menu: any[];
4040
editorInstance: any;
4141

4242
constructor(
4343
id: number,
44-
activeTab: ITab,
45-
tabs: ITab[],
44+
activeTab: ITab<T>,
45+
tabs: ITab<T>[],
4646
breadcrumb: any[] = [],
4747
actions: any[] = [],
4848
menu: any[] = [],
@@ -60,7 +60,7 @@ export class EditorGroupModel implements IEditorGroup {
6060

6161
@observable()
6262
@injectable()
63-
export class EditorModel implements IEditor {
63+
export class EditorModel<T> implements IEditor<T> {
6464
public current: IEditorGroup | undefined;
6565
public groups!: IEditorGroup[];
6666

@@ -78,7 +78,7 @@ export class EditorModel implements IEditor {
7878
public readonly onSelectTab = (tabKey: string, groupId?: number) => {
7979
EventBus.emit(EditorEvent.OnSelectTab, tabKey, groupId);
8080
};
81-
public readonly onMoveTab = (updateTabs: ITab[], groupId?: number) => {
81+
public readonly onMoveTab = (updateTabs: ITab<T>[], groupId?: number) => {
8282
EventBus.emit(EditorEvent.OnMoveTab, updateTabs, groupId);
8383
};
8484
public readonly onCloseTab = (tabKey?: string, groupId?: number) => {

src/services/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const activityBarService = container.resolve<IActivityBarService>(
3232
const explorerService = container.resolve<IExplorerService>(ExplorerService);
3333
const sidebarService = container.resolve<ISidebarService>(SidebarService);
3434
const menuBarService = container.resolve<IMenuBarService>(MenuBarService);
35-
const editorService = container.resolve<IEditorService>(EditorService);
35+
const editorService = container.resolve<IEditorService<any>>(EditorService);
3636
const statusBarService = container.resolve<IStatusBarService>(StatusBarService);
3737

3838
/**

src/services/workbench/editorService.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ import {
1111
IEditorGroup,
1212
} from 'mo/model';
1313

14-
export interface IEditorService extends Component<IEditor> {
14+
export interface IEditorService<T> extends Component<IEditor<T>> {
1515
/**
1616
* Open a new tab in indicated group instance
1717
* @param tab Tab data
1818
* @param groupId group ID
1919
*/
20-
open<T = any>(tab: ITab, groupId?: number): void;
20+
open<T = any>(tab: ITab<T>, groupId?: number): void;
2121
onCloseTab(callback: (tabKey?: string) => void);
22-
onMoveTab(callback: (tabs: ITab[]) => void);
22+
onMoveTab(callback: (tabs: ITab<T>[]) => void);
2323
onSelectTab(callback: (tabKey: string) => void);
2424
}
2525

2626
@singleton()
27-
export class EditorService
28-
extends Component<IEditor>
29-
implements IEditorService {
30-
protected state: IEditor;
27+
export class EditorService<T>
28+
extends Component<IEditor<T>>
29+
implements IEditorService<T> {
30+
protected state: IEditor<T>;
3131
constructor() {
3232
super();
3333
this.state = container.resolve(EditorModel);
@@ -51,7 +51,7 @@ export class EditorService
5151
}
5252

5353
@emit(EditorEvent.OpenTab)
54-
public open<T>(tab: ITab, groupId?: number) {
54+
public open<T>(tab: ITab<T>, groupId?: number) {
5555
let { current, groups } = this.state;
5656
let group: IEditorGroup | undefined = current;
5757
if (groupId) {
@@ -71,7 +71,7 @@ export class EditorService
7171
public onMoveTab(callback: (data) => void) {
7272
this.subscribe(
7373
EditorEvent.OnMoveTab,
74-
(tabs: ITab[], groupId?: number) => {
74+
(tabs: ITab<T>[], groupId?: number) => {
7575
let { groups } = this.state;
7676
let group;
7777
if (groupId === undefined) return;

src/workbench/editor/editor.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function renderGroups(
9292
return null;
9393
}
9494

95-
export function Editor(props: IEditor) {
95+
export function Editor<T>(props: IEditor<T>) {
9696
const {
9797
groups,
9898
render,

stories/workbench/0-Workbench.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import '../demo.scss';
55

66
export const IDEDemo = () => (
77
<MoleculeProvider extensions={customExtensions} locales={[]}>
8-
<Workbench />
8+
<Workbench/>
99
</MoleculeProvider>
1010
);
1111

0 commit comments

Comments
 (0)