GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: added onChangeViewType event to window model · DBvc/lowcode-engine@0184dcd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs/docs/api/model
    • window.md
  • packages
    • shell/src/model
      • window.ts
    • types/src/shell/model
      • window.ts
    • workspace/src
      • window.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/docs/api/model/window.md‎

Copy file name to clipboardExpand all lines: docs/docs/api/model/window.md
+12Lines changed: 12 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,15 @@ function changeViewType(viewName: string): void
6262
```typescript
6363
function save(): Promise(void)
6464
```
65+
66+
## 事件
67+
68+
### onChangeViewType
69+
70+
窗口视图变更事件
71+
72+
```
73+
onChangeViewType(fn: (viewName: string) => void): IPublicTypeDisposable;
74+
```
75+
76+
相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)
Collapse file

‎packages/shell/src/model/window.ts‎

Copy file name to clipboardExpand all lines: packages/shell/src/model/window.ts
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { windowSymbol } from '../symbols';
2-
import { IPublicModelResource, IPublicModelWindow } from '@alilc/lowcode-types';
2+
import { IPublicModelResource, IPublicModelWindow, IPublicTypeDisposable } from '@alilc/lowcode-types';
33
import { EditorWindow } from '@alilc/lowcode-workspace';
44
import { Resource as ShellResource } from './resource';
55

@@ -31,7 +31,11 @@ export class Window implements IPublicModelWindow {
3131
}
3232

3333
changeViewType(viewName: string) {
34-
this[windowSymbol].changeViewType(viewName);
34+
this[windowSymbol].changeViewType(viewName, false);
35+
}
36+
37+
onChangeViewType(fun: (viewName: string) => void): IPublicTypeDisposable {
38+
return this[windowSymbol].onChangeViewType(fun);
3539
}
3640

3741
async save() {
Collapse file

‎packages/types/src/shell/model/window.ts‎

Copy file name to clipboardExpand all lines: packages/types/src/shell/model/window.ts
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ReactElement } from 'react';
2-
import { IPublicTypeNodeSchema } from '../type';
2+
import { IPublicTypeDisposable, IPublicTypeNodeSchema } from '../type';
33
import { IPublicModelResource } from './resource';
44

55
export interface IPublicModelWindow {
@@ -24,4 +24,7 @@ export interface IPublicModelWindow {
2424

2525
/** 调用当前窗口视图保存钩子 */
2626
save(): Promise<any>;
27+
28+
/** 窗口视图变更事件 */
29+
onChangeViewType(fn: (viewName: string) => void): IPublicTypeDisposable;
2730
}
Collapse file

‎packages/workspace/src/window.ts‎

Copy file name to clipboardExpand all lines: packages/workspace/src/window.ts
+16-2Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { uniqueId } from '@alilc/lowcode-utils';
2-
import { makeObservable, obx } from '@alilc/lowcode-editor-core';
2+
import { createModuleEventBus, IEventBus, makeObservable, obx } from '@alilc/lowcode-editor-core';
33
import { Context } from './context/view-context';
44
import { Workspace } from './workspace';
55
import { Resource } from './resource';
6+
import { IPublicTypeDisposable } from '../../types/es/shell/type/disposable';
67

78
export class EditorWindow {
89
id: string = uniqueId('window');
910
icon: React.ReactElement | undefined;
1011

12+
private emitter: IEventBus = createModuleEventBus('Project');
13+
1114
@obx.ref editorView: Context;
1215

1316
@obx editorViews: Map<string, Context> = new Map<string, Context>();
@@ -59,6 +62,14 @@ export class EditorWindow {
5962
}
6063
};
6164

65+
onChangeViewType(fn: (viewName: string) => void): IPublicTypeDisposable {
66+
this.emitter.on('window.change.view.type', fn);
67+
68+
return () => {
69+
this.emitter.off('window.change.view.type', fn);
70+
};
71+
}
72+
6273
execViewTypesInit = async () => {
6374
const editorViews = this.resource.editorViews;
6475
for (let i = 0; i < editorViews.length; i++) {
@@ -81,10 +92,13 @@ export class EditorWindow {
8192
this.editorViews.set(name, editorView);
8293
};
8394

84-
changeViewType = (name: string) => {
95+
changeViewType = (name: string, ignoreEmit: boolean = true) => {
8596
this.editorView?.setActivate(false);
8697
this.editorView = this.editorViews.get(name)!;
8798

99+
if (!ignoreEmit) {
100+
this.emitter.emit('window.change.view.type', name);
101+
}
88102
this.editorView.setActivate(true);
89103
};
90104

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.