Skip to content

Commit 020efe8

Browse files
committed
Merge branch 'add-key-and-ref-to-tree-and-panel-view'
2 parents 3313ec3 + b69d1bb commit 020efe8

File tree

7 files changed

+51
-9
lines changed

7 files changed

+51
-9
lines changed

backend/getData.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function getData(element: Object): DataType {
2424
var updater = null;
2525
var name = null;
2626
var type = null;
27+
var key = null;
28+
var ref = null;
2729
var text = null;
2830
var publicInstance = null;
2931
var nodeType = 'Native';
@@ -60,6 +62,10 @@ function getData(element: Object): DataType {
6062
// != used deliberately here to catch undefined and null
6163
if (element._currentElement != null) {
6264
type = element._currentElement.type;
65+
if (element._currentElement.key) {
66+
key = String(element._currentElement.key);
67+
}
68+
ref = element._currentElement.ref;
6369
if (typeof type === 'string') {
6470
name = type;
6571
} else if (element.getName) {
@@ -103,6 +109,8 @@ function getData(element: Object): DataType {
103109
return {
104110
nodeType,
105111
type,
112+
key,
113+
ref,
106114
name,
107115
props,
108116
state,

backend/getData012.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function getData012(element: Object): DataType {
2121
var updater = null;
2222
var name = null;
2323
var type = null;
24+
var key = null;
25+
var ref = null;
2426
var text = null;
2527
var publicInstance = null;
2628
var nodeType = 'Native';
@@ -46,6 +48,10 @@ function getData012(element: Object): DataType {
4648

4749
if (element._currentElement) {
4850
type = element._currentElement.type;
51+
if (element._currentElement.key) {
52+
key = String(element._currentElement.key);
53+
}
54+
ref = element._currentElement.ref;
4955
if (typeof type === 'string') {
5056
name = type;
5157
} else {
@@ -83,6 +89,8 @@ function getData012(element: Object): DataType {
8389
return {
8490
nodeType,
8591
type,
92+
key,
93+
ref,
8694
name,
8795
props,
8896
state,

backend/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
export type DataType = {
1414
nodeType: 'Native' | 'Wrapper' | 'NativeWrapper' | 'Composite' | 'Text' | 'Empty',
1515
type: ?(string | AnyFn),
16+
key: ?string,
17+
ref: ?(string | AnyFn),
1618
name: ?string,
1719
props: ?Object,
1820
state: ?Object,

frontend/DataView/DataView.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ var styles = {
256256
fontSize: 8,
257257
cursor: 'pointer',
258258
position: 'absolute',
259+
top: '-2px',
259260
right: '100%',
260261
padding: '5px 0',
261262
},

frontend/Node.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ class Node extends React.Component {
144144
<span style={styles.tagText}>
145145
<span style={styles.openTag}>
146146
<span style={tagStyle}>&lt;{name}</span>
147-
{node.get('props') && <Props props={node.get('props')}/>}
147+
{node.get('key') && <Props key="key" props={{'key': node.get('key')}}/>}
148+
{node.get('ref') && <Props key="ref" props={{'ref': node.get('ref')}}/>}
149+
{node.get('props') && <Props key="props" props={node.get('props')}/>}
148150
{!content && '/'}
149151
<span style={tagStyle}>&gt;</span>
150152
</span>
@@ -160,11 +162,6 @@ class Node extends React.Component {
160162
);
161163
}
162164

163-
// Plain string
164-
if (typeof children === 'string') {
165-
return <div style={leftPad}>{children}</div>;
166-
}
167-
168165
var closeTag = (
169166
<span style={styles.closeTag}>
170167
<span style={tagStyle}>
@@ -196,7 +193,9 @@ class Node extends React.Component {
196193
<span style={styles.tagText}>
197194
<span style={styles.openTag}>
198195
<span style={tagStyle}>&lt;{'' + node.get('name')}</span>
199-
{node.get('props') && <Props props={node.get('props')}/>}
196+
{node.get('key') && <Props key="key" props={{'key': node.get('key')}}/>}
197+
{node.get('ref') && <Props key="ref" props={{'ref': node.get('ref')}}/>}
198+
{node.get('props') && <Props key="props" props={node.get('props')}/>}
200199
<span style={tagStyle}>&gt;</span>
201200
</span>
202201
{collapsed && '…'}

frontend/PropState.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var BlurInput = require('./BlurInput');
1414
var DataView = require('./DataView/DataView');
1515
var DetailPane = require('./detail_pane/DetailPane');
1616
var DetailPaneSection = require('./detail_pane/DetailPaneSection');
17+
var PropVal = require('./PropVal');
1718
var React = require('react');
1819

1920
var decorate = require('./decorate');
@@ -64,6 +65,8 @@ class PropState extends React.Component {
6465
}
6566
}
6667

68+
var key = this.props.node.get('key');
69+
var ref = this.props.node.get('ref');
6770
var state = this.props.node.get('state');
6871
var context = this.props.node.get('context');
6972
var propsReadOnly = !this.props.node.get('canUpdate');
@@ -72,6 +75,24 @@ class PropState extends React.Component {
7275
<DetailPane
7376
header={'<' + this.props.node.get('name') + '>'}
7477
hint="($r in the console)">
78+
{key &&
79+
<DetailPaneSection
80+
title="Key"
81+
key={this.props.id + '-key'}>
82+
<PropVal
83+
val={key}
84+
/>
85+
</DetailPaneSection>
86+
}
87+
{ref &&
88+
<DetailPaneSection
89+
title="Ref"
90+
key={this.props.id + '-ref'}>
91+
<PropVal
92+
val={ref}
93+
/>
94+
</DetailPaneSection>
95+
}
7596
{editTextContent}
7697
<DetailPaneSection
7798
hint={propsReadOnly ? 'read-only' : null}

frontend/detail_pane/DetailPaneSection.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class DetailPaneSection extends React.Component {
2020
} = this.props;
2121
return (
2222
<div style={styles.section}>
23-
<strong>{this.props.title}</strong>
24-
{hint ? ' ' + hint : null}
23+
<strong style={styles.title}>{this.props.title}</strong>
24+
{hint}
2525
{children}
2626
</div>
2727
);
@@ -33,6 +33,9 @@ var styles = {
3333
marginBottom: 10,
3434
flexShrink: 0,
3535
},
36+
title: {
37+
marginRight: 7,
38+
},
3639
};
3740

3841
module.exports = DetailPaneSection;

0 commit comments

Comments
 (0)