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

Function dehydrate

packages/react-devtools-shared/src/hydration.js:129–609  ·  view source on GitHub ↗
(
  data: Object,
  cleaned: Array<Array<string | number>>,
  unserializable: Array<Array<string | number>>,
  path: Array<string | number>,
  isPathAllowed: (path: Array<string | number>) => boolean,
  level: number = 0,
)

Source from the content-addressed store, hash-verified

127 * and cleaned = [["some", "attr"], ["other"]]
128 */
129export function dehydrate(
130 data: Object,
131 cleaned: Array<Array<string | number>>,
132 unserializable: Array<Array<string | number>>,
133 path: Array<string | number>,
134 isPathAllowed: (path: Array<string | number>) => boolean,
135 level: number = 0,
136): DehydratedData['data'] {
137 const type = getDataType(data);
138
139 let isPathAllowedCheck;
140
141 switch (type) {
142 case 'html_element':
143 cleaned.push(path);
144 return {
145 inspectable: false,
146 preview_short: formatDataForPreview(data, false),
147 preview_long: formatDataForPreview(data, true),
148 name: data.tagName,
149 type,
150 };
151
152 case 'function':
153 cleaned.push(path);
154 return {
155 inspectable: false,
156 preview_short: formatDataForPreview(data, false),
157 preview_long: formatDataForPreview(data, true),
158 name:
159 typeof data.name === 'function' || !data.name
160 ? 'function'
161 : data.name,
162 type,
163 };
164
165 case 'string':
166 isPathAllowedCheck = isPathAllowed(path);
167 if (isPathAllowedCheck) {
168 return data;
169 } else {
170 return data.length <= 500 ? data : data.slice(0, 500) + '...';
171 }
172
173 case 'bigint':
174 cleaned.push(path);
175 return {
176 inspectable: false,
177 preview_short: formatDataForPreview(data, false),
178 preview_long: formatDataForPreview(data, true),
179 name: data.toString(),
180 type,
181 };
182
183 case 'symbol':
184 cleaned.push(path);
185 return {
186 inspectable: false,

Callers 2

cleanForBridgeFunction · 0.90
dehydrateKeyFunction · 0.85

Calls 10

getDataTypeFunction · 0.90
formatDataForPreviewFunction · 0.90
getAllEnumerableKeysFunction · 0.90
createDehydratedFunction · 0.85
dehydrateKeyFunction · 0.85
pushMethod · 0.65
toStringMethod · 0.65
forEachMethod · 0.65
thenMethod · 0.65

Tested by

no test coverage detected