( plain: any, annotations: ReferentialEqualityAnnotations, version: number )
| 79 | } |
| 80 | |
| 81 | export function applyReferentialEqualityAnnotations( |
| 82 | plain: any, |
| 83 | annotations: ReferentialEqualityAnnotations, |
| 84 | version: number |
| 85 | ) { |
| 86 | const legacyPaths = enableLegacyPaths(version); |
| 87 | function apply(identicalPaths: string[], path: string) { |
| 88 | const object = getDeep(plain, parsePath(path, legacyPaths)); |
| 89 | |
| 90 | identicalPaths |
| 91 | .map(path => parsePath(path, legacyPaths)) |
| 92 | .forEach(identicalObjectPath => { |
| 93 | plain = setDeep(plain, identicalObjectPath, () => object); |
| 94 | }); |
| 95 | } |
| 96 | |
| 97 | if (isArray(annotations)) { |
| 98 | const [root, other] = annotations; |
| 99 | root.forEach(identicalPath => { |
| 100 | plain = setDeep( |
| 101 | plain, |
| 102 | parsePath(identicalPath, legacyPaths), |
| 103 | () => plain |
| 104 | ); |
| 105 | }); |
| 106 | |
| 107 | if (other) { |
| 108 | forEach(other, apply); |
| 109 | } |
| 110 | } else { |
| 111 | forEach(annotations, apply); |
| 112 | } |
| 113 | |
| 114 | return plain; |
| 115 | } |
| 116 | |
| 117 | const isDeep = (object: any, superJson: SuperJSON): boolean => |
| 118 | isPlainObject(object) || |
no test coverage detected
searching dependent graphs…