Feat:插件新增销毁前生命周期函数,解决销毁思维导图时插件的一些副作用没有清除的问题

This commit is contained in:
wanglin2
2023-08-27 10:34:15 +08:00
parent 8c0c2c5bc4
commit b35dd282ec
5 changed files with 24 additions and 0 deletions

View File

@@ -406,6 +406,9 @@ class MindMap {
destroy() {
// 移除插件
;[...MindMap.pluginList].forEach(plugin => {
if (this[plugin.instanceName].beforePluginDestroy) {
this[plugin.instanceName].beforePluginDestroy()
}
this[plugin.instanceName] = null
})
// 解绑事件
@@ -414,6 +417,7 @@ class MindMap {
this.svg.remove()
// 去除给容器元素设置的背景样式
Style.removeBackgroundStyle(this.el)
this.el.innerHTML = ''
this.el = null
}
}

View File

@@ -263,6 +263,11 @@ class NodeImgAdjust {
beforePluginRemove() {
this.unBindEvent()
}
// 插件被卸载前做的事情
beforePluginDestroy() {
this.unBindEvent()
}
}
NodeImgAdjust.instanceName = 'nodeImgAdjust'

View File

@@ -69,6 +69,11 @@ class Painter {
beforePluginRemove() {
this.unBindEvent()
}
// 插件被卸载前做的事情
beforePluginDestroy() {
this.unBindEvent()
}
}
Painter.instanceName = 'painter'

View File

@@ -631,6 +631,11 @@ class RichText {
this.transformAllNodesToNormalNode()
document.head.removeChild(this.styleEl)
}
// 插件被卸载前做的事情
beforePluginDestroy() {
document.head.removeChild(this.styleEl)
}
}
RichText.instanceName = 'richText'

View File

@@ -148,6 +148,11 @@ class TouchEvent {
beforePluginRemove() {
this.unBindEvent()
}
// 插件被卸载前做的事情
beforePluginDestroy() {
this.unBindEvent()
}
}
TouchEvent.instanceName = 'touchEvent'