Feat:被删除的节点同步从激活节点列表里删除;优化代码:1.移除父节点的连线逻辑合并到node.destroy方法内;2.提取render类中派发节点激活事件的重复代码

This commit is contained in:
wanglin2 2023-10-16 10:29:45 +08:00
parent 2c3fb4d7ea
commit 20157fcc8d
2 changed files with 18 additions and 12 deletions

View File

@ -387,10 +387,11 @@ class Render {
// 删除本次渲染时不再需要的节点
Object.keys(this.lastNodeCache).forEach(uid => {
if (!this.nodeCache[uid]) {
// 从激活节点列表里删除
this.removeNodeFromActiveList(this.lastNodeCache[uid])
this.emitNodeActiveEvent()
// 调用节点的销毁方法
this.lastNodeCache[uid].destroy()
if (this.lastNodeCache[uid].parent) {
this.lastNodeCache[uid].parent.removeLine()
}
}
})
// 更新根节点
@ -416,7 +417,7 @@ class Render {
}
})
})
this.mindMap.emit('node_active', null, [...this.activeNodeList])
this.emitNodeActiveEvent()
}
// 清除当前所有激活节点,并会触发事件
@ -475,7 +476,7 @@ class Render {
0,
0
)
this.mindMap.emit('node_active', null, [...this.activeNodeList])
this.emitNodeActiveEvent()
}
// 回退
@ -1019,7 +1020,7 @@ class Render {
if (needActiveNode) {
this.addNodeToActiveList(needActiveNode)
}
this.mindMap.emit('node_active', null, [...this.activeNodeList])
this.emitNodeActiveEvent()
this.mindMap.render()
}
@ -1062,7 +1063,7 @@ class Render {
if (needActiveNode) {
this.addNodeToActiveList(needActiveNode)
}
this.mindMap.emit('node_active', null, [...this.activeNodeList])
this.emitNodeActiveEvent()
this.mindMap.render()
}
@ -1143,7 +1144,7 @@ class Render {
removeFromParentNodeData(item)
toNode.nodeData.children.push(item.nodeData)
})
this.mindMap.emit('node_active', null, [...this.activeNodeList])
this.emitNodeActiveEvent()
this.mindMap.render()
}
@ -1535,6 +1536,11 @@ class Render {
})
return res
}
// 派发节点激活改变事件
emitNodeActiveEvent() {
this.mindMap.emit('node_active', null, [...this.activeNodeList])
}
}
export default Render

View File

@ -492,10 +492,7 @@ class Node {
}
// 如果有且只有当前节点激活了,那么不需要重新激活
if (
!(
this.getData('isActive') &&
this.renderer.activeNodeList.length === 1
)
!(this.getData('isActive') && this.renderer.activeNodeList.length === 1)
) {
this.renderer.clearActiveNodeList()
this.active(e)
@ -693,6 +690,9 @@ class Node {
this.removeGeneralization()
this.removeLine()
this.group = null
if (this.parent) {
this.parent.removeLine()
}
}
// 隐藏节点