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