MCPcopy Create free account
hub / github.com/RobPruzan/react-scratch / deepTraverseAndModify

Function deepTraverseAndModify

src/react/core.ts:1279–1315  ·  view source on GitHub ↗
(obj: any)

Source from the content-addressed store, hash-verified

1277};
1278
1279export function deepTraverseAndModify(obj: any): any {
1280 if (Array.isArray(obj)) {
1281 return obj.map(deepTraverseAndModify);
1282 } else if (typeof obj === "object" && obj !== null) {
1283 const newObj: any = {};
1284
1285 for (const [key, value] of Object.entries(obj)) {
1286 if (
1287 key === "computedViewTreeNode" &&
1288 value &&
1289 typeof value === "object" &&
1290 "id" in value
1291 ) {
1292 newObj["computedViewTreeNodeId"] = value.id;
1293 } else if (
1294 key === "internalMetadata" &&
1295 value &&
1296 typeof value === "object" &&
1297 "id" in value
1298 ) {
1299 let x = value as unknown as { component: any; id: string };
1300 newObj["internalMetadataName+Id"] = (
1301 x.component.tagName +
1302 x.component.name +
1303 "-" +
1304 x.id.slice(0, 4)
1305 ).replace("undefined", "");
1306 } else {
1307 newObj[key] = deepTraverseAndModify(value);
1308 }
1309 }
1310
1311 return newObj;
1312 }
1313
1314 return obj;
1315}
1316
1317export const buildReactTrees = (
1318 rootComponentInternalMetadata: ReactComponentInternalMetadata

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected