( self: Atom.Atom<AsyncResult.AsyncResult<A, E>> )
| 169 | */ |
| 170 | export const replaceEqualDeep = (prev: any, next: any): any => { |
| 171 | if (prev === next) return prev |
| 172 | const bothArrays = Array.isArray(prev) && Array.isArray(next) |
| 173 | if (bothArrays || (isPlainObject(prev) && isPlainObject(next))) { |
| 174 | const a: Record<PropertyKey, any> = prev |
| 175 | const b: Record<PropertyKey, any> = next |
| 176 | const copy: Record<PropertyKey, any> = bothArrays ? [] : {} |
| 177 | const nextKeys: Array<PropertyKey> = bothArrays ? (b as Array<any>).map((_, i) => i) : Object.keys(b) |
| 178 | const nextSize = nextKeys.length |
| 179 | const prevSize = bothArrays ? (a as Array<any>).length : Object.keys(a).length |
| 180 | let equalItems = 0 |
| 181 | for (let i = 0; i < nextSize; i++) { |
| 182 | const key = nextKeys[i]! |
| 183 | copy[key] = replaceEqualDeep(a[key], b[key]) |
| 184 | if (copy[key] === a[key] && a[key] !== undefined) equalItems++ |
| 185 | } |
| 186 | return prevSize === nextSize && equalItems === prevSize ? prev : copy |
no test coverage detected
searching dependent graphs…