MCPcopy
hub / github.com/facebook/react / createDehydrated

Function createDehydrated

packages/react-devtools-shared/src/hydration.js:76–109  ·  view source on GitHub ↗

* Generate the dehydrated metadata for complex object instances

(
  type: string,
  inspectable: boolean,
  data: Object,
  cleaned: Array<Array<string | number>>,
  path: Array<string | number>,
)

Source from the content-addressed store, hash-verified

74 * Generate the dehydrated metadata for complex object instances
75 */
76function createDehydrated(
77 type: string,
78 inspectable: boolean,
79 data: Object,
80 cleaned: Array<Array<string | number>>,
81 path: Array<string | number>,
82): Dehydrated {
83 cleaned.push(path);
84
85 const dehydrated: Dehydrated = {
86 inspectable,
87 type,
88 preview_long: formatDataForPreview(data, true),
89 preview_short: formatDataForPreview(data, false),
90 name:
91 typeof data.constructor !== 'function' ||
92 typeof data.constructor.name !== 'string' ||
93 data.constructor.name === 'Object'
94 ? ''
95 : data.constructor.name,
96 };
97
98 if (type === 'array' || type === 'typed_array') {
99 dehydrated.size = data.length;
100 } else if (type === 'object') {
101 dehydrated.size = Object.keys(data).length;
102 }
103
104 if (type === 'iterator' || type === 'typed_array') {
105 dehydrated.readonly = true;
106 }
107
108 return dehydrated;
109}
110
111/**
112 * Strip out complex data (instances, functions, and data nested > LEVEL_THRESHOLD levels deep).

Callers 1

dehydrateFunction · 0.85

Calls 3

formatDataForPreviewFunction · 0.90
keysMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected