(
from: readonly T[],
to: readonly T[],
mapConstructor: WeakMapConstructor | MapConstructor = WeakMap,
)
| 43 | mapConstructor: MapConstructor, |
| 44 | ): [(item: T) => 'added' | 'removed' | null, T[]] |
| 45 | export 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 | |
| 69 | export function getStackDiffMap<T extends object>( |
| 70 | from: readonly T[], |
no test coverage detected
searching dependent graphs…