代码优化:将调用clearAllActive方法的地方改为调用CLEAR_ACTIVE_NODE命令

This commit is contained in:
wanglin2
2023-10-13 10:55:02 +08:00
parent caedfb46a9
commit c68d629b7a
3 changed files with 16 additions and 16 deletions

View File

@@ -234,7 +234,7 @@ class MindMap {
// 设置主题
setTheme(theme, notRender = false) {
this.renderer.clearAllActive()
this.execCommand('CLEAR_ACTIVE_NODE')
this.opt.theme = theme
if (!notRender) {
this.render(null, CONSTANTS.CHANGE_THEME)
@@ -381,7 +381,7 @@ class MindMap {
this.opt.readonly = mode === CONSTANTS.MODE.READONLY
if (this.opt.readonly) {
// 取消当前激活的元素
this.renderer.clearAllActive()
this.execCommand('CLEAR_ACTIVE_NODE')
}
this.emit('mode_change', mode)
}

View File

@@ -202,8 +202,8 @@ class Render {
this.setNodeActive = this.setNodeActive.bind(this)
this.mindMap.command.add('SET_NODE_ACTIVE', this.setNodeActive)
// 清除所有激活节点
this.clearAllActive = this.clearAllActive.bind(this)
this.mindMap.command.add('CLEAR_ACTIVE_NODE', this.clearAllActive)
this.clearActiveNode = this.clearActiveNode.bind(this)
this.mindMap.command.add('CLEAR_ACTIVE_NODE', this.clearActiveNode)
// 切换节点是否展开
this.setNodeExpand = this.setNodeExpand.bind(this)
this.mindMap.command.add('SET_NODE_EXPAND', this.setNodeExpand)
@@ -400,6 +400,15 @@ class Render {
this.mindMap.emit('node_active', null, [...this.activeNodeList])
}
// 清除当前所有激活节点,并会触发事件
clearActiveNode() {
if (this.activeNodeList.length <= 0) {
return
}
this.clearActive()
this.mindMap.emit('node_active', null, [])
}
// 清除当前激活的节点
clearActive() {
this.activeNodeList.forEach(item => {
@@ -408,15 +417,6 @@ class Render {
this.activeNodeList = []
}
// 清除当前所有激活节点,并会触发事件
clearAllActive() {
if (this.activeNodeList.length <= 0) {
return
}
this.clearActive()
this.mindMap.emit('node_active', null, [])
}
// 添加节点到激活列表里
addActiveNode(node) {
let index = this.findActiveNodeIndex(node)
@@ -467,7 +467,7 @@ class Render {
// 回退
back(step) {
this.clearAllActive()
this.mindMap.execCommand('CLEAR_ACTIVE_NODE')
let data = this.mindMap.command.back(step)
if (data) {
this.renderTree = data
@@ -477,7 +477,7 @@ class Render {
// 前进
forward(step) {
this.clearAllActive()
this.mindMap.execCommand('CLEAR_ACTIVE_NODE')
let data = this.mindMap.command.forward(step)
if (data) {
this.renderTree = data

View File

@@ -222,7 +222,7 @@ class Drag extends Base {
// 创建克隆节点
this.createCloneNode()
// 清除当前所有激活的节点
this.mindMap.renderer.clearAllActive()
this.mindMap.execCommand('CLEAR_ACTIVE_NODE')
}
}