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

Function deepCloneTree

src/utils.ts:41–72  ·  view source on GitHub ↗
(obj: T, seen = new WeakSet())

Source from the content-addressed store, hash-verified

39};
40
41export const deepCloneTree = <T>(obj: T, seen = new WeakSet()): T => {
42 if (obj === null || typeof obj !== "object") {
43 return obj;
44 }
45
46 if (obj instanceof HTMLElement) {
47 return obj;
48 }
49
50 if (typeof obj === "function") {
51 return (obj as any).bind({});
52 }
53
54 if (seen.has(obj)) {
55 return obj as T; //
56 }
57
58 seen.add(obj);
59
60 const copy: any = Array.isArray(obj) ? [] : {};
61
62 for (const key in obj) {
63 if (obj.hasOwnProperty(key)) {
64 copy[key] = deepCloneTree(obj[key], seen);
65 }
66 }
67
68
69 seen.delete(obj);
70
71 return copy;
72};
73
74
75export const findNodeOrThrow = <T extends { id: string; childNodes: Array<T> }>(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected