MCPcopy Create free account
hub / github.com/thetarnav/solid-devtools / getDiffMap

Function getDiffMap

packages/logger/src/utils.ts:45–67  ·  view source on GitHub ↗
(
    from: readonly T[],
    to: readonly T[],
    mapConstructor: WeakMapConstructor | MapConstructor = WeakMap,
)

Source from the content-addressed store, hash-verified

43 mapConstructor: MapConstructor,
44): [(item: T) => 'added' | 'removed' | null, T[]]
45export function getDiffMap<T extends object>(
46 from: readonly T[],
47 to: readonly T[],
48 mapConstructor: WeakMapConstructor | MapConstructor = WeakMap,
49): [(item: T) => 'added' | 'removed' | null, T[]] {
50 const marks: Map<T, 'added' | 'removed'> = new (mapConstructor as any)()
51 const allItems: T[] = []
52 const toCopy = [...to]
53
54 from.forEach(owner => {
55 const index = toCopy.indexOf(owner)
56 if (index !== -1) toCopy.splice(index, 1)
57 else marks.set(owner, 'removed')
58 allItems.push(owner)
59 })
60 toCopy.forEach(owner => {
61 if (allItems.includes(owner)) return
62 marks.set(owner, 'added')
63 allItems.push(owner)
64 })
65
66 return [item => marks.get(item) || null, allItems]
67}
68
69export function getStackDiffMap<T extends object>(
70 from: readonly T[],

Callers 2

debugPropsFunction · 0.90
logOwnersDiffFunction · 0.90

Calls 1

getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…