Feat:编辑文本实时更新增加防抖操作,避免快速输入时不必要的计算
This commit is contained in:
parent
4a5501f7a3
commit
f34de3acd9
@ -33,6 +33,7 @@ import {
|
|||||||
formatGetNodeGeneralization,
|
formatGetNodeGeneralization,
|
||||||
sortNodeList,
|
sortNodeList,
|
||||||
throttle,
|
throttle,
|
||||||
|
debounce,
|
||||||
checkClipboardReadEnable,
|
checkClipboardReadEnable,
|
||||||
isNodeNotNeedRenderData
|
isNodeNotNeedRenderData
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
@ -161,7 +162,7 @@ class Render {
|
|||||||
this.mindMap.on('view_data_change', onViewDataChange)
|
this.mindMap.on('view_data_change', onViewDataChange)
|
||||||
}
|
}
|
||||||
// 文本编辑时实时更新节点大小
|
// 文本编辑时实时更新节点大小
|
||||||
this.onNodeTextEditChange = this.onNodeTextEditChange.bind(this)
|
this.onNodeTextEditChange = debounce(this.onNodeTextEditChange, 100, this)
|
||||||
if (openRealtimeRenderOnNodeTextEdit) {
|
if (openRealtimeRenderOnNodeTextEdit) {
|
||||||
this.mindMap.on('node_text_edit_change', this.onNodeTextEditChange)
|
this.mindMap.on('node_text_edit_change', this.onNodeTextEditChange)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -290,6 +290,21 @@ export const throttle = (fn, time = 300, ctx) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 防抖函数
|
||||||
|
export const debounce = (fn, wait = 300, ctx) => {
|
||||||
|
let timeout = null
|
||||||
|
|
||||||
|
return (...args) => {
|
||||||
|
if (timeout) clearTimeout(timeout)
|
||||||
|
const callNow = !timeout
|
||||||
|
timeout = setTimeout(() => {
|
||||||
|
timeout = null
|
||||||
|
fn.apply(ctx, args)
|
||||||
|
}, wait)
|
||||||
|
if (callNow) fn.apply(ctx, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 异步执行任务队列
|
// 异步执行任务队列
|
||||||
export const asyncRun = (taskList, callback = () => {}) => {
|
export const asyncRun = (taskList, callback = () => {}) => {
|
||||||
let index = 0
|
let index = 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user