MCPcopy Index your code
hub / github.com/tldraw/tldraw / getDiff

Function getDiff

apps/examples/src/misc/diff.ts:8–26  ·  view source on GitHub ↗
(prev: any, next: any, prefix = '', diff: any = {})

Source from the content-addressed store, hash-verified

6}
7
8export function getDiff(prev: any, next: any, prefix = '', diff: any = {}) {
9 const allKeys = new Set([...Object.keys(prev), ...Object.keys(next)])
10 if (prefix === '') {
11 diff['id'] = { prev: prev.id, next: next.id }
12 }
13 for (const key of allKeys) {
14 const prevValue = prev[key]
15 const nextValue = next[key]
16 const keyPath = format(prefix, key)
17 if (prevValue !== nextValue) {
18 if (typeof prevValue === 'object' && typeof nextValue === 'object') {
19 getDiff(prevValue, nextValue, keyPath, diff)
20 } else {
21 diff[keyPath] = { prev: prev[key], next: next[key] }
22 }
23 }
24 }
25 return diff
26}

Callers 1

afterChangeHandlerFunction · 0.90

Calls 2

formatFunction · 0.70
keysMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…