mirror of
https://github.com/langgenius/dify.git
synced 2026-08-28 20:26:50 +08:00
use cloneDeep instead of json.parse
This commit is contained in:
parent
1472884eb5
commit
7c3f6dcc8d
@ -1,5 +1,5 @@
|
|||||||
import { LoroDoc, UndoManager } from 'loro-crdt'
|
import { LoroDoc, UndoManager } from 'loro-crdt'
|
||||||
import { isEqual } from 'lodash-es'
|
import { cloneDeep, isEqual } from 'lodash-es'
|
||||||
import { webSocketClient } from './websocket-manager'
|
import { webSocketClient } from './websocket-manager'
|
||||||
import { CRDTProvider } from './crdt-provider'
|
import { CRDTProvider } from './crdt-provider'
|
||||||
import { EventEmitter } from './event-emitter'
|
import { EventEmitter } from './event-emitter'
|
||||||
@ -582,7 +582,7 @@ export class CollaborationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (value !== null && typeof value === 'object')
|
if (value !== null && typeof value === 'object')
|
||||||
target[prop as string] = JSON.parse(JSON.stringify(value))
|
target[prop as string] = cloneDeep(value)
|
||||||
else
|
else
|
||||||
target[prop as string] = value
|
target[prop as string] = value
|
||||||
})
|
})
|
||||||
@ -609,7 +609,7 @@ export class CollaborationManager {
|
|||||||
// Clone data properties, excluding private ones
|
// Clone data properties, excluding private ones
|
||||||
Object.entries(newNode.data).forEach(([key, value]) => {
|
Object.entries(newNode.data).forEach(([key, value]) => {
|
||||||
if (shouldSyncDataKey(key) && value !== undefined)
|
if (shouldSyncDataKey(key) && value !== undefined)
|
||||||
nodeData.data[key] = JSON.parse(JSON.stringify(value))
|
nodeData.data[key] = cloneDeep(value)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.nodesMap.set(newNode.id, nodeData)
|
this.nodesMap.set(newNode.id, nodeData)
|
||||||
@ -620,7 +620,7 @@ export class CollaborationManager {
|
|||||||
|
|
||||||
if (existingNode) {
|
if (existingNode) {
|
||||||
// Create a deep copy to modify
|
// Create a deep copy to modify
|
||||||
const updatedNode = JSON.parse(JSON.stringify(existingNode))
|
const updatedNode = cloneDeep(existingNode)
|
||||||
|
|
||||||
// Update position only if changed
|
// Update position only if changed
|
||||||
if (oldNode.position.x !== newNode.position.x || oldNode.position.y !== newNode.position.y)
|
if (oldNode.position.x !== newNode.position.x || oldNode.position.y !== newNode.position.y)
|
||||||
@ -649,7 +649,7 @@ export class CollaborationManager {
|
|||||||
if (shouldSyncDataKey(key)) {
|
if (shouldSyncDataKey(key)) {
|
||||||
const oldValue = (oldData as any)[key]
|
const oldValue = (oldData as any)[key]
|
||||||
if (!isEqual(oldValue, value))
|
if (!isEqual(oldValue, value))
|
||||||
updatedNode.data[key] = JSON.parse(JSON.stringify(value))
|
updatedNode.data[key] = cloneDeep(value)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -680,7 +680,7 @@ export class CollaborationManager {
|
|||||||
|
|
||||||
Object.entries(newNode.data).forEach(([key, value]) => {
|
Object.entries(newNode.data).forEach(([key, value]) => {
|
||||||
if (shouldSyncDataKey(key) && value !== undefined)
|
if (shouldSyncDataKey(key) && value !== undefined)
|
||||||
nodeData.data[key] = JSON.parse(JSON.stringify(value))
|
nodeData.data[key] = cloneDeep(value)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.nodesMap.set(newNode.id, nodeData)
|
this.nodesMap.set(newNode.id, nodeData)
|
||||||
@ -703,11 +703,11 @@ export class CollaborationManager {
|
|||||||
newEdges.forEach((newEdge) => {
|
newEdges.forEach((newEdge) => {
|
||||||
const oldEdge = oldEdgesMap.get(newEdge.id)
|
const oldEdge = oldEdgesMap.get(newEdge.id)
|
||||||
if (!oldEdge) {
|
if (!oldEdge) {
|
||||||
const clonedEdge = JSON.parse(JSON.stringify(newEdge))
|
const clonedEdge = cloneDeep(newEdge)
|
||||||
this.edgesMap.set(newEdge.id, clonedEdge)
|
this.edgesMap.set(newEdge.id, clonedEdge)
|
||||||
}
|
}
|
||||||
else if (!isEqual(oldEdge, newEdge)) {
|
else if (!isEqual(oldEdge, newEdge)) {
|
||||||
const clonedEdge = JSON.parse(JSON.stringify(newEdge))
|
const clonedEdge = cloneDeep(newEdge)
|
||||||
this.edgesMap.set(newEdge.id, clonedEdge)
|
this.edgesMap.set(newEdge.id, clonedEdge)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user