Feat:修改协同编辑节点操作的更新逻辑
This commit is contained in:
parent
792811f39e
commit
e22f67a831
@ -136,30 +136,43 @@ class Cooperate {
|
|||||||
this.currentData = data
|
this.currentData = data
|
||||||
this.ydoc.transact(() => {
|
this.ydoc.transact(() => {
|
||||||
// 找出新增的或修改的
|
// 找出新增的或修改的
|
||||||
|
const createOrUpdateList = []
|
||||||
Object.keys(data).forEach(uid => {
|
Object.keys(data).forEach(uid => {
|
||||||
// 新增的或已经存在的,如果数据发生了改变
|
// 新增的或已经存在的,如果数据发生了改变
|
||||||
if (!oldData[uid] || !isSameObject(oldData[uid], data[uid])) {
|
if (!oldData[uid] || !isSameObject(oldData[uid], data[uid])) {
|
||||||
if (beforeCooperateUpdate) {
|
createOrUpdateList.push({
|
||||||
beforeCooperateUpdate({
|
uid,
|
||||||
type: 'createOrUpdate',
|
data: data[uid],
|
||||||
data: data[uid]
|
oldData: oldData[uid],
|
||||||
})
|
})
|
||||||
}
|
|
||||||
this.ymap.set(uid, data[uid])
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if (beforeCooperateUpdate && createOrUpdateList.length > 0) {
|
||||||
|
beforeCooperateUpdate({
|
||||||
|
type: 'createOrUpdate',
|
||||||
|
list: createOrUpdateList,
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
createOrUpdateList.forEach(item => {
|
||||||
|
this.ymap.set(item.uid, item.data)
|
||||||
|
})
|
||||||
// 找出删除的
|
// 找出删除的
|
||||||
|
const deleteList = []
|
||||||
Object.keys(oldData).forEach(uid => {
|
Object.keys(oldData).forEach(uid => {
|
||||||
if (!data[uid]) {
|
if (!data[uid]) {
|
||||||
if (beforeCooperateUpdate) {
|
deleteList.push({ uid, data: oldData[uid] })
|
||||||
beforeCooperateUpdate({
|
|
||||||
type: 'delete',
|
|
||||||
data: oldData[uid]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.ymap.delete(uid)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if (beforeCooperateUpdate && deleteList.length > 0) {
|
||||||
|
beforeCooperateUpdate({
|
||||||
|
type: 'delete',
|
||||||
|
list: deleteList
|
||||||
|
})
|
||||||
|
}
|
||||||
|
deleteList.forEach(item => {
|
||||||
|
this.ymap.delete(item.uid)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user