Compare commits
3 Commits
f5cb19dfa4
...
abab44ad24
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
abab44ad24 | ||
|
|
849b561933 | ||
|
|
1031595a97 |
@@ -55,7 +55,7 @@
|
|||||||
"cz-conventional-changelog": "^3.3.0",
|
"cz-conventional-changelog": "^3.3.0",
|
||||||
"element-plus": "^2.9.11",
|
"element-plus": "^2.9.11",
|
||||||
"enquirer": "^2.4.1",
|
"enquirer": "^2.4.1",
|
||||||
"eslint": "^9.34.0",
|
"eslint": "^9.35.0",
|
||||||
"execa": "^4.1.0",
|
"execa": "^4.1.0",
|
||||||
"highlight.js": "^11.11.1",
|
"highlight.js": "^11.11.1",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
"vitepress": "^1.6.4",
|
"vitepress": "^1.6.4",
|
||||||
"vitest": "^3.2.4",
|
"vitest": "^3.2.4",
|
||||||
"vue": "catalog:",
|
"vue": "catalog:",
|
||||||
"vue-tsc": "^3.0.6"
|
"vue-tsc": "^3.0.7"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"commitizen": {
|
"commitizen": {
|
||||||
|
|||||||
@@ -167,8 +167,13 @@ class App extends EventEmitter {
|
|||||||
this.setPage(pageId);
|
this.setPage(pageId);
|
||||||
|
|
||||||
if (this.dataSourceManager) {
|
if (this.dataSourceManager) {
|
||||||
const dataSourceList = Array.from(this.dataSourceManager.dataSourceMap.values());
|
if (this.dataSourceManager.isAllDataSourceRegistered()) {
|
||||||
this.eventHelper?.bindDataSourceEvents(dataSourceList);
|
this.eventHelper?.bindDataSourceEvents();
|
||||||
|
} else {
|
||||||
|
this.dataSourceManager.once('registered-all', () => {
|
||||||
|
this.eventHelper?.bindDataSourceEvents();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,21 +113,23 @@ export default class EventHelper extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public removeNodeEvents() {
|
public removeNodeEvents() {
|
||||||
Array.from(this.nodeEventList.keys()).forEach((handler) => {
|
for (const handler of Array.from(this.nodeEventList.keys())) {
|
||||||
const name = this.nodeEventList.get(handler);
|
const name = this.nodeEventList.get(handler);
|
||||||
name && this.off(name, handler);
|
name && this.off(name, handler);
|
||||||
});
|
}
|
||||||
|
|
||||||
this.nodeEventList.clear();
|
this.nodeEventList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bindDataSourceEvents(dataSourceList: DataSource[]) {
|
public bindDataSourceEvents() {
|
||||||
|
const dataSourceList = Array.from(this.app.dataSourceManager?.dataSourceMap.values() || []);
|
||||||
|
|
||||||
this.removeDataSourceEvents(dataSourceList);
|
this.removeDataSourceEvents(dataSourceList);
|
||||||
|
|
||||||
dataSourceList.forEach((dataSource) => {
|
for (const dataSource of dataSourceList) {
|
||||||
const dataSourceEvent = this.dataSourceEventList.get(dataSource.id) ?? new Map<string, (args: any) => void>();
|
const dataSourceEvent = this.dataSourceEventList.get(dataSource.id) ?? new Map<string, (args: any) => void>();
|
||||||
|
|
||||||
(dataSource.schema.events || []).forEach((event) => {
|
for (const event of dataSource.schema.events || []) {
|
||||||
const [prefix, ...path] = event.name?.split('.') || [];
|
const [prefix, ...path] = event.name?.split('.') || [];
|
||||||
if (!prefix) return;
|
if (!prefix) return;
|
||||||
const handler = (...args: any[]) => {
|
const handler = (...args: any[]) => {
|
||||||
@@ -141,9 +143,9 @@ export default class EventHelper extends EventEmitter {
|
|||||||
// 数据源自定义事件
|
// 数据源自定义事件
|
||||||
dataSource.on(prefix, handler);
|
dataSource.on(prefix, handler);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
this.dataSourceEventList.set(dataSource.id, dataSourceEvent);
|
this.dataSourceEventList.set(dataSource.id, dataSourceEvent);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeDataSourceEvents(dataSourceList: DataSource[]) {
|
public removeDataSourceEvents(dataSourceList: DataSource[]) {
|
||||||
@@ -152,20 +154,20 @@ export default class EventHelper extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 先清掉之前注册的事件,重新注册
|
// 先清掉之前注册的事件,重新注册
|
||||||
dataSourceList.forEach((dataSource) => {
|
for (const dataSource of dataSourceList) {
|
||||||
const dataSourceEvent = this.dataSourceEventList.get(dataSource.id)!;
|
const dataSourceEvent = this.dataSourceEventList.get(dataSource.id)!;
|
||||||
|
|
||||||
if (!dataSourceEvent) return;
|
if (!dataSourceEvent) return;
|
||||||
|
|
||||||
Array.from(dataSourceEvent.keys()).forEach((eventName) => {
|
for (const eventName of Array.from(dataSourceEvent.keys())) {
|
||||||
const [prefix, ...path] = eventName.split('.');
|
const [prefix, ...path] = eventName.split('.');
|
||||||
if (prefix === DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX) {
|
if (prefix === DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX) {
|
||||||
dataSource.offDataChange(path.join('.'), dataSourceEvent.get(eventName)!);
|
dataSource.offDataChange(path.join('.'), dataSourceEvent.get(eventName)!);
|
||||||
} else {
|
} else {
|
||||||
dataSource.off(prefix, dataSourceEvent.get(eventName)!);
|
dataSource.off(prefix, dataSourceEvent.get(eventName)!);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
this.dataSourceEventList.clear();
|
this.dataSourceEventList.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ export class DeepObservedData extends ObservedData {
|
|||||||
update = (data: any, path?: string) => {
|
update = (data: any, path?: string) => {
|
||||||
this.state?.update(path ?? '', data);
|
this.state?.update(path ?? '', data);
|
||||||
};
|
};
|
||||||
on = (path: string, callback: (newVal: any) => void) => {
|
on = (path: string, callback: (newVal: any) => void, options?: { immediate?: boolean }) => {
|
||||||
// subscribe 会立即执行一次,ignoreFirstCall 会忽略第一次执行
|
// subscribe 会立即执行一次,ignoreFirstCall 会忽略第一次执行
|
||||||
const unsubscribe = this.state!.subscribe(path, ignoreFirstCall(callback));
|
const unsubscribe = this.state!.subscribe(path, options?.immediate ? callback : ignoreFirstCall(callback));
|
||||||
|
|
||||||
// 把取消监听的函数保存下来,供 off 时调用
|
// 把取消监听的函数保存下来,供 off 时调用
|
||||||
const pathSubscribers = this.subscribers.get(path) ?? new Map<Function, () => void>();
|
const pathSubscribers = this.subscribers.get(path) ?? new Map<Function, () => void>();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export abstract class ObservedData {
|
export abstract class ObservedData {
|
||||||
abstract update(data: any, path?: string): void;
|
abstract update(data: any, path?: string): void;
|
||||||
|
|
||||||
abstract on(path: string, callback: (newVal: any) => void): void;
|
abstract on(path: string, callback: (newVal: any) => void, options?: { immediate?: boolean }): void;
|
||||||
|
|
||||||
abstract off(path: string, callback: (newVal: any) => void): void;
|
abstract off(path: string, callback: (newVal: any) => void): void;
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,10 @@ export class SimpleObservedData extends ObservedData {
|
|||||||
this.event.emit('', changeEvent);
|
this.event.emit('', changeEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
on(path: string, callback: (newVal: any) => void): void {
|
on(path: string, callback: (newVal: any) => void, options?: { immediate?: boolean }): void {
|
||||||
|
if (options?.immediate) {
|
||||||
|
callback(this.getData(path));
|
||||||
|
}
|
||||||
this.event.on(path, callback);
|
this.event.on(path, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
515
pnpm-lock.yaml
generated
515
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -7,8 +7,8 @@ packages:
|
|||||||
- 'eslint-config'
|
- 'eslint-config'
|
||||||
|
|
||||||
catalog:
|
catalog:
|
||||||
vue: ^3.5.20
|
vue: ^3.5.21
|
||||||
'@vue/compiler-sfc': ^3.5.20
|
'@vue/compiler-sfc': ^3.5.20
|
||||||
vite: ^7.1.3
|
vite: ^7.1.5
|
||||||
typescript: "^5.9.2"
|
typescript: "^5.9.2"
|
||||||
|
|
||||||
Reference in New Issue
Block a user