| 1124 | * Production code should use diffEach() to avoid allocations. |
| 1125 | */ |
| 1126 | export function diff( |
| 1127 | prev: Screen, |
| 1128 | next: Screen, |
| 1129 | ): [point: Point, removed: Cell | undefined, added: Cell | undefined][] { |
| 1130 | const output: [Point, Cell | undefined, Cell | undefined][] = [] |
| 1131 | diffEach(prev, next, (x, y, removed, added) => { |
| 1132 | // Copy cells since diffEach reuses the objects |
| 1133 | output.push([ |
| 1134 | { x, y }, |
| 1135 | removed ? { ...removed } : undefined, |
| 1136 | added ? { ...added } : undefined, |
| 1137 | ]) |
| 1138 | }) |
| 1139 | return output |
| 1140 | } |
| 1141 | |
| 1142 | type DiffCallback = ( |
| 1143 | x: number, |