MCPcopy
hub / github.com/tldraw/tldraw / getNetworkDiff

Function getNetworkDiff

packages/sync-core/src/lib/diff.ts:74–98  ·  view source on GitHub ↗
(
	diff: RecordsDiff<R>
)

Source from the content-addressed store, hash-verified

72 * @internal
73 */
74export function getNetworkDiff<R extends UnknownRecord>(
75 diff: RecordsDiff<R>
76): NetworkDiff<R> | null {
77 let res: NetworkDiff<R> | null = null
78
79 for (const [k, v] of objectMapEntries(diff.added)) {
80 if (!res) res = {}
81 res[k] = [RecordOpType.Put, v]
82 }
83
84 for (const [from, to] of objectMapValues(diff.updated)) {
85 const diff = diffRecord(from, to)
86 if (diff) {
87 if (!res) res = {}
88 res[to.id] = [RecordOpType.Patch, diff]
89 }
90 }
91
92 for (const removed of Object.keys(diff.removed)) {
93 if (!res) res = {}
94 res[removed] = [RecordOpType.Remove]
95 }
96
97 return res
98}
99
100/**
101 * Constants representing the types of operations that can be applied to individual values

Callers 4

constructorMethod · 0.90
didReconnectMethod · 0.90
TLSyncClientClass · 0.90
diff.test.tsFile · 0.90

Calls 4

objectMapEntriesFunction · 0.90
objectMapValuesFunction · 0.90
diffRecordFunction · 0.85
keysMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…