1
0
mirror of synced 2025-12-12 12:57:57 +08:00

refactor: 及时释放没用变量

This commit is contained in:
roymondchen
2024-08-26 14:24:12 +08:00
committed by roymondchen
parent 0be82bedee
commit ee469dfd65
4 changed files with 12 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
import { nextTick, reactive, ref } from 'vue-demi';
import { nextTick, onBeforeUnmount, reactive, ref } from 'vue-demi';
import Core from '@tmagic/core';
import type { ChangeEvent } from '@tmagic/data-source';
@@ -8,7 +8,7 @@ import { isPage, replaceChildNode } from '@tmagic/utils';
export const useDsl = (app: Core | undefined) => {
const pageConfig = ref(app?.page?.data || {});
app?.dataSourceManager?.on('update-data', (nodes: MNode[], sourceId: string, changeEvent: ChangeEvent) => {
const updateDataHandler = (nodes: MNode[], sourceId: string, changeEvent: ChangeEvent) => {
nodes.forEach((node) => {
if (isPage(node)) {
pageConfig.value = node;
@@ -22,6 +22,12 @@ export const useDsl = (app: Core | undefined) => {
nextTick(() => {
app.emit('replaced-node', { nodes, sourceId, ...changeEvent });
});
};
app?.dataSourceManager?.on('update-data', updateDataHandler);
onBeforeUnmount(() => {
app?.dataSourceManager?.off('update-data', updateDataHandler);
});
return {