(object, path, replace)
| 1322 | // Returns something analogous to object, but with the appropriate |
| 1323 | // pointers inflated. |
| 1324 | function replacePointers(object, path, replace) { |
| 1325 | if (Array.isArray(object)) { |
| 1326 | return object |
| 1327 | .map(obj => replacePointers(obj, path, replace)) |
| 1328 | .filter(obj => typeof obj !== 'undefined'); |
| 1329 | } |
| 1330 | |
| 1331 | if (typeof object !== 'object' || !object) { |
| 1332 | return object; |
| 1333 | } |
| 1334 | |
| 1335 | if (path.length === 0) { |
| 1336 | if (object && object.__type === 'Pointer') { |
| 1337 | return replace[object.objectId]; |
| 1338 | } |
| 1339 | return object; |
| 1340 | } |
| 1341 | |
| 1342 | var subobject = object[path[0]]; |
| 1343 | if (!subobject) { |
| 1344 | return object; |
| 1345 | } |
| 1346 | var newsub = replacePointers(subobject, path.slice(1), replace); |
| 1347 | var answer = {}; |
| 1348 | for (var key in object) { |
| 1349 | if (key == path[0]) { |
| 1350 | answer[key] = newsub; |
| 1351 | } else { |
| 1352 | answer[key] = object[key]; |
| 1353 | } |
| 1354 | } |
| 1355 | return answer; |
| 1356 | } |
| 1357 | |
| 1358 | // Finds a subobject that has the given key, if there is one. |
| 1359 | // Returns undefined otherwise. |
no test coverage detected
searching dependent graphs…