|
1 |
| -import { HasUrlObject } from "./model.ts"; |
| 1 | +import { HasUrlObject } from "./model"; |
| 2 | +import equal from "fast-deep-equal/es6"; |
2 | 3 |
|
3 | 4 | /**
|
4 | 5 | * A special value which indicates that the difference between two objects is Irreconcilable.
|
@@ -186,30 +187,14 @@ function diffPrimitive<T extends { [key: string]: any }>(
|
186 | 187 | const yKeys = Object.keys(y);
|
187 | 188 | const deletedKeys = setDifference(xKeys, yKeys);
|
188 | 189 | const addedKeys = setDifference(yKeys, xKeys);
|
189 |
| - const changedKeys = xKeys.filter((key) => !deepishEqual(x[key], y[key])); |
| 190 | + const changedKeys = xKeys.filter((key) => !equal(x[key], y[key])); |
190 | 191 | const diffKeys = addedKeys.concat(changedKeys);
|
191 | 192 | return {
|
192 | 193 | ...Object.fromEntries(deletedKeys.map((key) => [key, undefined])),
|
193 | 194 | ...Object.fromEntries(diffKeys.map((key) => [key, y[key]])),
|
194 | 195 | };
|
195 | 196 | }
|
196 | 197 |
|
197 |
| -/** |
198 |
| - * Equality for arrays and primitives. |
199 |
| - */ |
200 |
| -function deepishEqual<T>(x: T, y: T): boolean { |
201 |
| - if (Array.isArray(x)) { |
202 |
| - if (!Array.isArray(y)) { |
203 |
| - return false; |
204 |
| - } |
205 |
| - return zipArrays(x, y).reduce( |
206 |
| - (same, [a, b]) => same && deepishEqual(a, b), |
207 |
| - true, |
208 |
| - ); |
209 |
| - } |
210 |
| - return x === y; |
211 |
| -} |
212 |
| - |
213 | 198 | function zipArrays<X, Y>(x: X[], y: Y[]): [X, Y][] {
|
214 | 199 | return x.map((v, i) => [v, y[i]]);
|
215 | 200 | }
|
|
0 commit comments