Stricter types for DataDescription

Summary: Made datatypes used by DataInspector more strictly typed (in the hope to be able to drop some, but all are still in use, although the distinction between different elements isn't always clear).

Reviewed By: passy

Differential Revision: D27266825

fbshipit-source-id: 6a1c74b0ae3daff6299ca598b18a205d17c42e22
This commit is contained in:
Michel Weststrate
2021-04-07 07:52:47 -07:00
committed by Facebook GitHub Bot
parent eabf0fc340
commit 07c4470ab9
4 changed files with 31 additions and 8 deletions

View File

@@ -99,7 +99,10 @@ export {
export {default as DataInspector} from './ui/components/data-inspector/DataInspector';
export {default as ManagedDataInspector} from './ui/components/data-inspector/ManagedDataInspector';
export {default as SearchableDataInspector} from './ui/components/data-inspector/SearchableDataInspector';
export {default as DataDescription} from './ui/components/data-inspector/DataDescription';
export {
default as DataDescription,
DataDescriptionType,
} from './ui/components/data-inspector/DataDescription';
export {HighlightManager} from './ui/components/Highlight';
export {default as Tabs} from './ui/components/Tabs';
export {default as Tab} from './ui/components/Tab';

View File

@@ -85,9 +85,28 @@ const EmptyObjectValue = styled.span({
});
EmptyObjectValue.displayName = 'DataDescription:EmptyObjectValue';
export type DataDescriptionType =
| 'number'
| 'string'
| 'boolean'
| 'undefined'
| 'null'
| 'object'
| 'array'
| 'date'
| 'symbol'
| 'function'
| 'bigint'
| 'text' // deprecated, please use string
| 'enum' // unformatted string
| 'color'
| 'picker' // multiple choise item like an, eehhh, enum
| 'timeline'
| 'color_lite'; // color with limited palette, specific for fblite;
type DataDescriptionProps = {
path?: Array<string>;
type: string;
type: DataDescriptionType;
value: any;
extra?: any;
setValue: DataInspectorSetValue | null | undefined;
@@ -102,7 +121,7 @@ type DescriptionCommitOptions = {
class NumberTextEditor extends PureComponent<{
commit: (opts: DescriptionCommitOptions) => void;
type: string;
type: DataDescriptionType;
value: any;
origValue: any;
}> {
@@ -447,7 +466,7 @@ class ColorEditor extends PureComponent<{
}
class DataDescriptionPreview extends PureComponent<{
type: string;
type: DataDescriptionType;
value: any;
extra?: any;
editable: boolean;
@@ -551,7 +570,7 @@ type Picker = {
};
class DataDescriptionContainer extends PureComponent<{
type: string;
type: DataDescriptionType;
value: any;
editable: boolean;
commit: (opts: DescriptionCommitOptions) => void;

View File

@@ -7,7 +7,7 @@
* @format
*/
import DataDescription from './DataDescription';
import DataDescription, {DataDescriptionType} from './DataDescription';
import styled from '@emotion/styled';
import {getSortedKeys} from './utils';
import {PureComponent} from 'react';
@@ -21,7 +21,7 @@ export type DataValueExtractor = (
) =>
| {
mutable: boolean;
type: string;
type: DataDescriptionType;
value: any;
extra?: any;
}

View File

@@ -20,6 +20,7 @@ import {
FlipperPlugin,
Button,
styled,
DataDescriptionType,
} from 'flipper';
import {Element} from 'flipper';
import {processLeaks} from './processLeakString';
@@ -163,7 +164,7 @@ export default class LeakCanary<PersistedState> extends FlipperPlugin<
_extractValue(
value: any,
_: number, // depth
): {mutable: boolean; type: string; value: any} {
): {mutable: boolean; type: DataDescriptionType; value: any} {
if (!isNaN(value)) {
return {mutable: false, type: 'number', value: value};
} else if (value == 'true' || value == 'false') {