mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-11-18 20:42:38 +08:00
fix(editor): services在组件unmounted时只重置状态不移除事件
This commit is contained in:
parent
67c7faf832
commit
45a20d9405
@ -316,13 +316,12 @@ export default defineComponent({
|
|||||||
);
|
);
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
editorService.destroy();
|
editorService.resetState();
|
||||||
historyService.destroy();
|
historyService.resetState();
|
||||||
propsService.destroy();
|
propsService.resetState();
|
||||||
uiService.destroy();
|
uiService.resetState();
|
||||||
componentListService.destroy();
|
componentListService.resetState();
|
||||||
storageService.destroy();
|
codeBlockService.resetState();
|
||||||
codeBlockService.destroy();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const services: Services = {
|
const services: Services = {
|
||||||
|
|||||||
@ -344,7 +344,7 @@ class CodeBlock extends BaseService {
|
|||||||
this.setCodeDsl(codeDsl);
|
this.setCodeDsl(codeDsl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public destroy(): void {
|
public resetState() {
|
||||||
this.state.isShowCodeEditor = false;
|
this.state.isShowCodeEditor = false;
|
||||||
this.state.codeDsl = null;
|
this.state.codeDsl = null;
|
||||||
this.state.id = '';
|
this.state.id = '';
|
||||||
@ -354,6 +354,12 @@ class CodeBlock extends BaseService {
|
|||||||
this.state.undeletableList = [];
|
this.state.undeletableList = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public destroy(): void {
|
||||||
|
this.resetState();
|
||||||
|
this.removeAllListeners();
|
||||||
|
this.removeAllPlugins();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除组件时 如果是容器 需要遍历删除其包含节点的绑定信息
|
* 删除组件时 如果是容器 需要遍历删除其包含节点的绑定信息
|
||||||
* @param {MNode} node 节点信息
|
* @param {MNode} node 节点信息
|
||||||
|
|||||||
@ -42,9 +42,14 @@ class ComponentList extends BaseService {
|
|||||||
return this.state.list;
|
return this.state.list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public destroy() {
|
public resetState() {
|
||||||
this.state.list = [];
|
this.state.list = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public destroy() {
|
||||||
|
this.resetState();
|
||||||
this.removeAllListeners();
|
this.removeAllListeners();
|
||||||
|
this.removeAllPlugins();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -207,7 +207,7 @@ class Editor extends BaseService {
|
|||||||
if (page) {
|
if (page) {
|
||||||
historyService.changePage(toRaw(page));
|
historyService.changePage(toRaw(page));
|
||||||
} else {
|
} else {
|
||||||
historyService.empty();
|
historyService.resetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node?.id) {
|
if (node?.id) {
|
||||||
@ -762,8 +762,7 @@ class Editor extends BaseService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public destroy() {
|
public resetState() {
|
||||||
this.removeAllListeners();
|
|
||||||
this.set('root', null);
|
this.set('root', null);
|
||||||
this.set('node', null);
|
this.set('node', null);
|
||||||
this.set('nodes', []);
|
this.set('nodes', []);
|
||||||
@ -775,6 +774,12 @@ class Editor extends BaseService {
|
|||||||
this.set('pageLength', new Map());
|
this.set('pageLength', new Map());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public destroy() {
|
||||||
|
this.removeAllListeners();
|
||||||
|
this.resetState();
|
||||||
|
this.removeAllPlugins();
|
||||||
|
}
|
||||||
|
|
||||||
public resetModifiedNodeId() {
|
public resetModifiedNodeId() {
|
||||||
this.get<Map<Id, Id>>('modifiedNodeIds').clear();
|
this.get<Map<Id, Id>>('modifiedNodeIds').clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,10 +76,15 @@ class Events extends BaseService {
|
|||||||
return cloneDeep(methodMap[type] || DEFAULT_METHODS);
|
return cloneDeep(methodMap[type] || DEFAULT_METHODS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public destroy() {
|
public resetState() {
|
||||||
eventMap = reactive({});
|
eventMap = reactive({});
|
||||||
methodMap = reactive({});
|
methodMap = reactive({});
|
||||||
|
}
|
||||||
|
|
||||||
|
public destroy() {
|
||||||
|
this.resetState();
|
||||||
this.removeAllListeners();
|
this.removeAllListeners();
|
||||||
|
this.removeAllPlugins();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -68,7 +68,7 @@ class History extends BaseService {
|
|||||||
this.emit('page-change', this.state.pageSteps[this.state.pageId]);
|
this.emit('page-change', this.state.pageSteps[this.state.pageId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public empty(): void {
|
public resetState(): void {
|
||||||
this.state.pageId = undefined;
|
this.state.pageId = undefined;
|
||||||
this.state.pageSteps = {};
|
this.state.pageSteps = {};
|
||||||
this.state.canRedo = false;
|
this.state.canRedo = false;
|
||||||
@ -100,8 +100,9 @@ class History extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public destroy(): void {
|
public destroy(): void {
|
||||||
this.empty();
|
this.resetState();
|
||||||
this.removeAllListeners();
|
this.removeAllListeners();
|
||||||
|
this.removeAllPlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
private getUndoRedo() {
|
private getUndoRedo() {
|
||||||
|
|||||||
@ -171,10 +171,15 @@ class Props extends BaseService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public destroy() {
|
public resetState() {
|
||||||
this.state.propsConfigMap = {};
|
this.state.propsConfigMap = {};
|
||||||
this.state.propsValueMap = {};
|
this.state.propsValueMap = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
public destroy() {
|
||||||
|
this.resetState();
|
||||||
this.removeAllListeners();
|
this.removeAllListeners();
|
||||||
|
this.removeAllPlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -109,6 +109,7 @@ export class WebStorage extends BaseService {
|
|||||||
|
|
||||||
public destroy() {
|
public destroy() {
|
||||||
this.removeAllListeners();
|
this.removeAllListeners();
|
||||||
|
this.removeAllPlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
private getValueAndProtocol(value: string | null) {
|
private getValueAndProtocol(value: string | null) {
|
||||||
|
|||||||
@ -97,8 +97,20 @@ class Ui extends BaseService {
|
|||||||
return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
|
return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public resetState() {
|
||||||
|
this.set('showSrc', false);
|
||||||
|
this.set('uiSelectMode', false);
|
||||||
|
this.set('zoom', 1);
|
||||||
|
this.set('stageContainerRect', {
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public destroy() {
|
public destroy() {
|
||||||
|
this.resetState();
|
||||||
this.removeAllListeners();
|
this.removeAllListeners();
|
||||||
|
this.removeAllPlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async setStageRect(value: StageRect) {
|
private async setStageRect(value: StageRect) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user