mirror of
https://github.com/wanglin2/mind-map.git
synced 2026-02-17 14:04:47 +08:00
Feat:编辑文本实时更新增加防抖操作,避免快速输入时不必要的计算
This commit is contained in:
@@ -33,6 +33,7 @@ import {
|
||||
formatGetNodeGeneralization,
|
||||
sortNodeList,
|
||||
throttle,
|
||||
debounce,
|
||||
checkClipboardReadEnable,
|
||||
isNodeNotNeedRenderData
|
||||
} from '../../utils'
|
||||
@@ -161,7 +162,7 @@ class Render {
|
||||
this.mindMap.on('view_data_change', onViewDataChange)
|
||||
}
|
||||
// 文本编辑时实时更新节点大小
|
||||
this.onNodeTextEditChange = this.onNodeTextEditChange.bind(this)
|
||||
this.onNodeTextEditChange = debounce(this.onNodeTextEditChange, 100, this)
|
||||
if (openRealtimeRenderOnNodeTextEdit) {
|
||||
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 = () => {}) => {
|
||||
let index = 0
|
||||
|
||||
Reference in New Issue
Block a user