| 43 | |
| 44 | /** @internal */ |
| 45 | export const diff = ( |
| 46 | oldValue: FiberRefs.FiberRefs, |
| 47 | newValue: FiberRefs.FiberRefs |
| 48 | ): FiberRefsPatch.FiberRefsPatch => { |
| 49 | const missingLocals = new Map(oldValue.locals) |
| 50 | let patch = empty |
| 51 | for (const [fiberRef, pairs] of newValue.locals.entries()) { |
| 52 | const newValue = Arr.headNonEmpty(pairs)[1] |
| 53 | const old = missingLocals.get(fiberRef) |
| 54 | if (old !== undefined) { |
| 55 | const oldValue = Arr.headNonEmpty(old)[1] |
| 56 | if (!equals(oldValue, newValue)) { |
| 57 | patch = combine({ |
| 58 | _tag: OP_UPDATE, |
| 59 | fiberRef, |
| 60 | patch: fiberRef.diff(oldValue, newValue) |
| 61 | })(patch) |
| 62 | } |
| 63 | } else { |
| 64 | patch = combine({ |
| 65 | _tag: OP_ADD, |
| 66 | fiberRef, |
| 67 | value: newValue |
| 68 | })(patch) |
| 69 | } |
| 70 | missingLocals.delete(fiberRef) |
| 71 | } |
| 72 | for (const [fiberRef] of missingLocals.entries()) { |
| 73 | patch = combine({ |
| 74 | _tag: OP_REMOVE, |
| 75 | fiberRef |
| 76 | })(patch) |
| 77 | } |
| 78 | return patch |
| 79 | } |
| 80 | |
| 81 | /** @internal */ |
| 82 | export const combine = dual< |