Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 10e4f68

Browse files
committed
Merge pull request #138 from jaredly/symbol-props-support
fix #127; add support for Symbols in props
2 parents f21aebd + 20994ab commit 10e4f68

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

agent/dehydrate.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ function dehydrate(data: Object, cleaned: Array<Array<string>>, path?: Array<str
4444
if (typeof data === 'string' && data.length > 500) {
4545
return data.slice(0, 500) + '...';
4646
}
47+
// We have to do this assignment b/c Flow doesn't think "symbol" is
48+
// something typeof would return. Error 'unexpected predicate "symbol"'
49+
var type = typeof data;
50+
if (type === 'symbol') {
51+
cleaned.push(path);
52+
return {
53+
type: 'symbol',
54+
name: data.toString(),
55+
};
56+
}
4757
return data;
4858
}
4959
if (data._reactFragment) {

frontend/DataView/previewComplex.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ function previewComplex(data: Object) {
4141
{data[consts.name] + '{}'}
4242
</span>
4343
);
44+
} else if (type === 'symbol') {
45+
return (
46+
<span style={valueStyles.symbol}>
47+
{data[consts.name]}
48+
</span>
49+
);
4450
}
4551
}
4652

frontend/PropVal.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ function previewProp(val: any, nested: boolean) {
7676
if (type === 'array') {
7777
return <span>Array[{val[consts.meta].length}]</span>;
7878
}
79+
if (type === 'symbol') {
80+
// the name is "Symbol(something)"
81+
return <span style={valueStyles.symbol}>{val[consts.name]}</span>;
82+
}
7983
}
8084
if (nested) {
8185
return <span>{'{…}'}</span>;

frontend/value-styles.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ module.exports = {
2626
color: 'rgb(0, 154, 190)',
2727
},
2828

29+
symbol: {
30+
color: 'rgb(232, 98, 0)',
31+
},
32+
2933
number: {
3034
color: 'rgb(255, 0, 252)',
3135
},

test/example/build/sink.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/example/sink.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ class Nester extends React.Component {
5454
}
5555
}
5656

57+
class SymbolProp {
58+
render() {
59+
return (
60+
<div sym={Symbol("name")}>
61+
This tests that dehydration + inspection works with symbols
62+
{Symbol("child")}
63+
</div>
64+
);
65+
}
66+
}
67+
5768
class BadUnmount {
5869
render() {
5970
return (
@@ -125,6 +136,7 @@ class LotsOfMounts {
125136
class Sink {
126137
render() {
127138
var examples = {
139+
SymbolProp,
128140
LongRender,
129141
DeepTree,
130142
BadUnmount,

0 commit comments

Comments
 (0)