阻止短时间多次触发渲染

This commit is contained in:
wanglin2 2023-03-31 22:25:34 +08:00
parent 8d9299aed7
commit 4cd9b66653

View File

@ -34,6 +34,11 @@ class Render {
this.renderTree = merge({}, this.mindMap.opt.data || {}) this.renderTree = merge({}, this.mindMap.opt.data || {})
// 是否重新渲染 // 是否重新渲染
this.reRender = false this.reRender = false
// 是否正在渲染中
this.isRendering = false
// 是否存在等待渲染
this.hasWaitRendering = false
// 用于缓存节点
this.nodeCache = {} this.nodeCache = {}
this.lastNodeCache = {} this.lastNodeCache = {}
// 触发render的来源 // 触发render的来源
@ -237,6 +242,13 @@ class Render {
// 渲染 // 渲染
render(callback = () => {}, source) { render(callback = () => {}, source) {
// 如果当前还没有渲染完毕,不再触发渲染
if (this.isRendering) {
// 等待当前渲染完毕后再进行一次渲染
this.hasWaitRendering = true
return
}
this.isRendering = true
// 触发当前重新渲染的来源 // 触发当前重新渲染的来源
this.renderSource = source this.renderSource = source
// 节点缓存 // 节点缓存
@ -261,8 +273,13 @@ class Render {
this.root = root this.root = root
// 渲染节点 // 渲染节点
this.root.render(() => { this.root.render(() => {
this.isRendering = false
this.mindMap.emit('node_tree_render_end') this.mindMap.emit('node_tree_render_end')
callback && callback() callback && callback()
if (this.hasWaitRendering) {
this.hasWaitRendering = false
this.render(callback, source)
}
}) })
}) })
this.mindMap.emit('node_active', null, this.activeNodeList) this.mindMap.emit('node_active', null, this.activeNodeList)