Skip to content

Commit

Permalink
fix: add bigint data type in hydration
Browse files Browse the repository at this point in the history
  • Loading branch information
nutboltu committed Nov 1, 2019
1 parent ea44d1f commit 5932fb3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 67 deletions.
43 changes: 0 additions & 43 deletions packages/react-devtools-shared/src/__tests__/backend/utils-test.js

This file was deleted.

25 changes: 1 addition & 24 deletions packages/react-devtools-shared/src/backend/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,6 @@ import {dehydrate} from '../hydration';

import type {DehydratedData} from 'react-devtools-shared/src/devtools/views/Components/types';

export function getSerializableData(data: any) {
if (data === null) {
return data;
}
// $FlowFixMe
if (typeof data === 'bigint') {
return data.toString() + 'n';
}
if (Array.isArray(data)) {
return data.reduce(function(acc, val) {
acc.push(getSerializableData(val));
return acc;
}, []);
}
if (typeof data === 'object') {
return Object.keys(data).reduce(function(acc, key) {
acc[key] = getSerializableData(data[key]);
return acc;
}, {});
}
return data;
}

export function cleanForBridge(
data: Object | null,
isPathWhitelisted: (path: Array<string | number>) => boolean,
Expand All @@ -49,7 +26,7 @@ export function cleanForBridge(
path,
isPathWhitelisted,
);

console.log(cleanedData);
return {
data: cleanedData,
cleaned: cleanedPaths,
Expand Down
2 changes: 2 additions & 0 deletions packages/react-devtools-shared/src/devtools/views/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export function getMetaValueLabel(data: Object): string | null {
case 'date':
case 'symbol':
return name;
case 'bigint':
return `${name}n`;
case 'iterator':
return `${name}(…)`;
case 'array_buffer':
Expand Down
11 changes: 11 additions & 0 deletions packages/react-devtools-shared/src/hydration.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const LEVEL_THRESHOLD = 2;
type PropType =
| 'array'
| 'array_buffer'
| 'bigint'
| 'boolean'
| 'data_view'
| 'date'
Expand Down Expand Up @@ -107,6 +108,8 @@ function getDataType(data: Object): PropType {

const type = typeof data;
switch (type) {
case 'bigint':
return 'bigint';
case 'boolean':
return 'boolean';
case 'function':
Expand Down Expand Up @@ -231,6 +234,14 @@ export function dehydrate(
case 'string':
return data.length <= 500 ? data : data.slice(0, 500) + '...';

case 'bigint':
cleaned.push(path);
return {
inspectable: false,
name: data.toString(),
type,
};

case 'symbol':
cleaned.push(path);
return {
Expand Down

0 comments on commit 5932fb3

Please sign in to comment.