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

Commit f3fc4cb

Browse files
committed
make inspect() mutate, remove need to pass window
1 parent a1c6b61 commit f3fc4cb

File tree

9 files changed

+51
-36
lines changed

9 files changed

+51
-36
lines changed

agent/Bridge.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,17 +329,19 @@ class Bridge {
329329
result[name] = dehydrate(val[name], cleaned, [name]);
330330
});
331331

332-
if (!protod && val.__proto__ && val.constructor.name !== 'Object') { // eslint-disable-line no-proto
332+
// eslint-disable no-proto
333+
if (!protod && val.__proto__ && val.constructor.name !== 'Object') {
333334
proto = {};
334-
var pIsFn = typeof val.__proto__ === 'function'; // eslint-disable-line no-proto
335-
Object.getOwnPropertyNames(val.__proto__).forEach(name => { // eslint-disable-line no-proto
335+
var pIsFn = typeof val.__proto__ === 'function';
336+
Object.getOwnPropertyNames(val.__proto__).forEach(name => {
336337
if (pIsFn && (name === 'arguments' || name === 'callee' || name === 'caller')) {
337338
return;
338339
}
339340
// $FlowFixMe flow thinks proto (and val) might be null
340-
proto[name] = dehydrate(val.__proto__[name], protoclean, [name]); // eslint-disable-line no-proto
341+
proto[name] = dehydrate(val.__proto__[name], protoclean, [name]);
341342
});
342343
}
344+
// eslint-enable no-proto
343345
}
344346

345347
this._wall.send({

frontend/Container.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import type MenuItem from './ContextMenu';
2121
class Container extends React.Component {
2222
props: {
2323
reload: () => void,
24-
win: Object,
2524
extraPanes: Array<(node: Object) => ReactElement>,
2625
menuItems: {
2726
tree?: (id: string, node: Object, store: Object) => ?Array<MenuItem>,
@@ -67,8 +66,7 @@ class Container extends React.Component {
6766
<div style={styles.container}>
6867
<SplitPane
6968
initialWidth={300}
70-
win={this.props.win}
71-
left={() => <SearchPane win={this.props.win} reload={this.props.reload} />}
69+
left={() => <SearchPane reload={this.props.reload} />}
7270
right={() => <PropState extraPanes={this.props.extraPanes} />}
7371
/>
7472
<ContextMenu itemSources={[defaultItems, this.props.menuItems]} />

frontend/DataView/DataView.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ class DataItem extends React.Component {
8080

8181
inspect() {
8282
this.setState({loading: true, open: true});
83-
this.props.inspect(this.props.path, value => {
84-
assign(this.props.value, value);
85-
this.props.value[consts.inspected] = true;
83+
this.props.inspect(this.props.path, () => {
8684
this.setState({loading: false});
8785
});
8886
}
@@ -107,7 +105,7 @@ class DataItem extends React.Component {
107105

108106
var complex = true;
109107
var preview;
110-
if (otype === 'number' || otype === 'string' || data === null || data === undefined || otype === 'boolean') {
108+
if (otype === 'number' || otype === 'string' || data == null /* null or undefined */ || otype === 'boolean') {
111109
preview = (
112110
<Simple
113111
readOnly={this.props.readOnly}

frontend/DataView/Simple.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Simple extends React.Component {
4343
}
4444
}
4545

46-
onSubmit(editing?: boolean) {
46+
onSubmit(editing: boolean) {
4747
if (this.state.text === valueToText(this.props.data)) {
4848
this.setState({
4949
editing: editing,
@@ -97,7 +97,7 @@ class Simple extends React.Component {
9797
ref={i => this.input = i}
9898
style={styles.input}
9999
onChange={e => this.onChange(e)}
100-
onBlur={() => this.onSubmit()}
100+
onBlur={() => this.onSubmit(false)}
101101
onKeyDown={this.onKeyDown.bind(this)}
102102
value={this.state.text}
103103
/>
@@ -112,14 +112,12 @@ class Simple extends React.Component {
112112
typeStyle = valueStyles.bool;
113113
} else if (!this.props.data) {
114114
typeStyle = valueStyles.empty;
115-
}
116-
if (type === 'string') {
115+
} else if (type === 'string') {
117116
typeStyle = valueStyles.string;
118117
if (data.length > 200) {
119118
data = data.slice(0, 200) + '…';
120119
}
121-
}
122-
if (type === 'number') {
120+
} else if (type === 'number') {
123121
typeStyle = valueStyles.number;
124122
}
125123
style = assign({}, style, typeStyle);

frontend/Draggable.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class Draggable {
2525

2626
_startDragging(evt: DOMEvent) {
2727
evt.preventDefault();
28-
var win = this.props.win || window;
29-
win.addEventListener('mousemove', this._onMove);
30-
win.addEventListener('mouseup', this._onUp);
28+
var doc = React.findDOMNode(this).ownerDocument;
29+
doc.addEventListener('mousemove', this._onMove);
30+
doc.addEventListener('mouseup', this._onUp);
3131
this.props.onStart();
3232
}
3333

@@ -38,9 +38,9 @@ class Draggable {
3838

3939
onUp(evt: DOMEvent) {
4040
evt.preventDefault();
41-
var win = this.props.win || window;
42-
win.removeEventListener('mousemove', this._onMove);
43-
win.removeEventListener('mouseup', this._onUp);
41+
var doc = React.findDOMNode(this).ownerDocument;
42+
doc.removeEventListener('mousemove', this._onMove);
43+
doc.removeEventListener('mouseup', this._onUp);
4444
this.props.onStop();
4545
}
4646

frontend/SearchPane.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,34 @@ type EventLike = {
2727
class SearchPane extends React.Component {
2828
input: ReactElement;
2929
_key: (evt: EventLike) => void;
30+
constructor(props) {
31+
super(props);
32+
this.state = {focused: false};
33+
}
3034

31-
componentWillMount() {
32-
this._key = this.onWindowKeyDown.bind(this);
33-
var win = this.props.win || window;
34-
win.addEventListener('keydown', this._key, true);
35+
componentDidMount() {
36+
this._key = this.onDocumentKeyDown.bind(this);
37+
var doc = React.findDOMNode(this).ownerDocument;
38+
doc.addEventListener('keydown', this._key, true);
3539
}
3640

3741
componentWillUnmount() {
38-
var win = this.props.win || window;
39-
win.removeEventListener('keydown', this._key, true);
42+
var doc = React.findDOMNode(this).ownerDocument;
43+
doc.removeEventListener('keydown', this._key, true);
4044
}
4145

42-
onWindowKeyDown(e) {
46+
onDocumentKeyDown(e) {
4347
if (e.keyCode === 191) { // forward slash
4448
var node = React.findDOMNode(this.input);
45-
var win = this.props.win || window;
46-
if (win.document.activeElement === node) {
49+
var doc = React.findDOMNode(this).ownerDocument;
50+
if (doc.activeElement === node) {
4751
return;
4852
}
4953
node.focus();
5054
e.preventDefault();
5155
}
5256
if (e.keyCode === 27) { // escape
53-
if (!this.props.searchText) {
57+
if (!this.props.searchText && !this.state.focused) {
5458
return;
5559
}
5660
e.stopPropagation();
@@ -82,6 +86,8 @@ class SearchPane extends React.Component {
8286
style={styles.input}
8387
ref={i => this.input = i}
8488
value={this.props.searchText}
89+
onFocus={() => this.setState({focused: true})}
90+
onBlur={() => this.setState({focused: false})}
8591
onKeyDown={e => this.onKeyDown(e.key)}
8692
placeholder="Search by Component Name"
8793
onChange={e => this.props.onChangeSearch(e.target.value)}

frontend/SplitPane.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class SplitPane extends React.Component {
4444
{/* $FlowFixMe the "extends React.Component" is just to help flow */}
4545
<Draggable
4646
style={dragStyle}
47-
win={this.props.win}
4847
onStart={() => this.setState({moving: true})}
4948
onMove={x => this.onMove(x)}
5049
onStop={() => this.setState({moving: false})}

frontend/Store.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ var {EventEmitter} = require('events');
1818
var {Map, Set, List} = require('immutable');
1919
var assign = require('object-assign');
2020
var nodeMatchesText = require('./nodeMatchesText');
21+
var consts = require('../agent/consts');
22+
var invariant = require('./invariant');
2123

2224
import type * as Bridge from '../agent/Bridge';
2325
import type {DOMEvent, ElementID} from './types';
@@ -350,8 +352,18 @@ class Store extends EventEmitter {
350352
this.removeListener(evt, fn);
351353
}
352354

353-
inspect(id: ElementID, path: Array<string>, cb: (val: any) => void) {
354-
this._bridge.inspect(id, path, cb);
355+
inspect(id: ElementID, path: Array<string>, cb: () => void) {
356+
invariant(path[0] === 'props' || path[0] === 'state' || path[0] === 'context',
357+
'Inspected path must be one of props, state, or context');
358+
this._bridge.inspect(id, path, value => {
359+
var base = this.get(id).get(path[0]);
360+
var inspected = path.slice(1).reduce((obj, attr) => obj ? obj[attr] : null, base);
361+
if (inspected) {
362+
assign(inspected, value);
363+
inspected[consts.inspected] = true;
364+
}
365+
cb();
366+
});
355367
}
356368

357369
// Private stuff

frontend/invariant.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*
9+
* TODO: this is copied from fbjs because fbjs doesn't play well with
10+
* non-haste module systems :/. Look into how to fix this.
911
*/
1012
'use strict';
1113

0 commit comments

Comments
 (0)