Skip to content

Commit

Permalink
feat: resovle #37
Browse files Browse the repository at this point in the history
  • Loading branch information
mumiao committed Dec 21, 2020
1 parent 3597665 commit dd2577d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
24 changes: 12 additions & 12 deletions src/model/workbench/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,39 @@ export enum EditorEvent {
OpenTab = 'editor.openTab',
OnSelectTab = 'editor.selectTab',
}
export interface IEditor {
export interface IEditor<T> {
current: IEditorGroup | undefined;
groups: IEditorGroup[];
closeAll?: () => void;
onCloseTab?: (tabKey?: string, group?: number) => void;
render?: () => React.ReactNode;
onMoveTab?: (tabs: ITab[], group?: number) => void;
onMoveTab?: (tabs: ITab<T>[], group?: number) => void;
onSelectTab?: (tabKey: string, group?: number) => void;
}

export interface IEditorGroup<E = any> {
export interface IEditorGroup<E = any, T = any> {
id: number;
activeTab: ITab;
tabs: ITab[];
activeTab: ITab<T>;
tabs: ITab<T>[];
breadcrumb: any[];
actions: any[];
menu: any[];
editorInstance?: E | null;
}

export class EditorGroupModel implements IEditorGroup {
export class EditorGroupModel<T> implements IEditorGroup<T> {
id: number;
activeTab: ITab;
tabs: ITab[];
activeTab: ITab<T>;
tabs: ITab<T>[];
breadcrumb: any[];
actions: any[];
menu: any[];
editorInstance: any;

constructor(
id: number,
activeTab: ITab,
tabs: ITab[],
activeTab: ITab<T>,
tabs: ITab<T>[],
breadcrumb: any[] = [],
actions: any[] = [],
menu: any[] = [],
Expand All @@ -60,7 +60,7 @@ export class EditorGroupModel implements IEditorGroup {

@observable()
@injectable()
export class EditorModel implements IEditor {
export class EditorModel<T> implements IEditor<T> {
public current: IEditorGroup | undefined;
public groups!: IEditorGroup[];

Expand All @@ -78,7 +78,7 @@ export class EditorModel implements IEditor {
public readonly onSelectTab = (tabKey: string, groupId?: number) => {
EventBus.emit(EditorEvent.OnSelectTab, tabKey, groupId);
};
public readonly onMoveTab = (updateTabs: ITab[], groupId?: number) => {
public readonly onMoveTab = (updateTabs: ITab<T>[], groupId?: number) => {
EventBus.emit(EditorEvent.OnMoveTab, updateTabs, groupId);
};
public readonly onCloseTab = (tabKey?: string, groupId?: number) => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const activityBarService = container.resolve<IActivityBarService>(
const explorerService = container.resolve<IExplorerService>(ExplorerService);
const sidebarService = container.resolve<ISidebarService>(SidebarService);
const menuBarService = container.resolve<IMenuBarService>(MenuBarService);
const editorService = container.resolve<IEditorService>(EditorService);
const editorService = container.resolve<IEditorService<any>>(EditorService);
const statusBarService = container.resolve<IStatusBarService>(StatusBarService);

/**
Expand Down
18 changes: 9 additions & 9 deletions src/services/workbench/editorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ import {
IEditorGroup,
} from 'mo/model';

export interface IEditorService extends Component<IEditor> {
export interface IEditorService<T> extends Component<IEditor<T>> {
/**
* Open a new tab in indicated group instance
* @param tab Tab data
* @param groupId group ID
*/
open<T = any>(tab: ITab, groupId?: number): void;
open<T = any>(tab: ITab<T>, groupId?: number): void;
onCloseTab(callback: (tabKey?: string) => void);
onMoveTab(callback: (tabs: ITab[]) => void);
onMoveTab(callback: (tabs: ITab<T>[]) => void);
onSelectTab(callback: (tabKey: string) => void);
}

@singleton()
export class EditorService
extends Component<IEditor>
implements IEditorService {
protected state: IEditor;
export class EditorService<T>
extends Component<IEditor<T>>
implements IEditorService<T> {
protected state: IEditor<T>;
constructor() {
super();
this.state = container.resolve(EditorModel);
Expand All @@ -51,7 +51,7 @@ export class EditorService
}

@emit(EditorEvent.OpenTab)
public open<T>(tab: ITab, groupId?: number) {
public open<T>(tab: ITab<T>, groupId?: number) {
let { current, groups } = this.state;
let group: IEditorGroup | undefined = current;
if (groupId) {
Expand All @@ -71,7 +71,7 @@ export class EditorService
public onMoveTab(callback: (data) => void) {
this.subscribe(
EditorEvent.OnMoveTab,
(tabs: ITab[], groupId?: number) => {
(tabs: ITab<T>[], groupId?: number) => {
let { groups } = this.state;
let group;
if (groupId === undefined) return;
Expand Down
2 changes: 1 addition & 1 deletion src/workbench/editor/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function renderGroups(
return null;
}

export function Editor(props: IEditor) {
export function Editor<T>(props: IEditor<T>) {
const {
groups,
render,
Expand Down
2 changes: 1 addition & 1 deletion stories/workbench/0-Workbench.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import '../demo.scss';

export const IDEDemo = () => (
<MoleculeProvider extensions={customExtensions} locales={[]}>
<Workbench />
<Workbench/>
</MoleculeProvider>
);

Expand Down

0 comments on commit dd2577d

Please sign in to comment.