Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions agent/Bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Bridge {
this._wall.listen(this._handleMessage.bind(this));
}

inspect(id: string, path: Array<string>, cb: (val: any) => any) {
inspect(id: string, path: Array<string>, immutablesAsJS: boolean, cb: (val: any) => any) {
var _cid = this._cid++;
this._cbs.set(_cid, (data, cleaned, proto, protoclean) => {
if (cleaned.length) {
Expand All @@ -152,6 +152,7 @@ class Bridge {
callback: _cid,
path,
id,
immutablesAsJS
});
}

Expand Down Expand Up @@ -259,7 +260,7 @@ class Bridge {
}

if (payload.type === 'inspect') {
this._inspectResponse(payload.id, payload.path, payload.callback);
this._inspectResponse(payload.id, payload.path, payload.immutablesAsJS, payload.callback);
return;
}

Expand Down Expand Up @@ -311,7 +312,7 @@ class Bridge {
});
}

_inspectResponse(id: string, path: Array<string>, callback: number) {
_inspectResponse(id: string, path: Array<string>, immutablesAsJS: boolean, callback: number) {
var val = getIn(this._inspectables.get(id), path);
var result = {};
var cleaned = [];
Expand All @@ -321,7 +322,7 @@ class Bridge {
var protod = false;
var isFn = typeof val === 'function';

if (immutableUtils.isImmutable(val)) {
if (immutablesAsJS && immutableUtils.isImmutable(val)) {
val = immutableUtils.shallowToJS(val);
}

Expand Down
1 change: 1 addition & 0 deletions agent/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
name: Symbol('name'),
type: Symbol('type'),
inspected: Symbol('inspected'),
immutablesAsJS: Symbol('immutablesAsJS'),
meta: Symbol('meta'),
proto: Symbol('proto'),
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Container extends React.Component {
<SplitPane
initialWidth={300}
left={() => <SearchPane reload={this.props.reload} />}
right={() => <PropState extraPanes={this.props.extraPanes} />}
right={() => <PropState reload={this.forceUpdate.bind(this)} extraPanes={this.props.extraPanes}/>}
/>
<ContextMenu itemSources={[defaultItems, this.props.menuItems]} />
</div>
Expand Down
15 changes: 13 additions & 2 deletions frontend/DataView/DataView.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,18 @@ class DataItem extends React.Component {
this.state = {open: false, loading: false};
}

shouldInspect(props) {
return (
props.value &&
(
props.value[consts.inspected] === false ||
props.value[consts.immutablesAsJS] !== props.immutablesAsJS
)
);
}

componentWillReceiveProps(nextProps) {
if (this.state.open && nextProps.value && nextProps.value[consts.inspected] === false) {
if (this.state.open && this.shouldInspect(nextProps)) {
this.inspect();
}
}
Expand All @@ -89,7 +99,7 @@ class DataItem extends React.Component {
if (this.state.loading) {
return;
}
if (this.props.value && this.props.value[consts.inspected] === false) {
if (this.shouldInspect(this.props)) {
this.inspect();
return;
}
Expand Down Expand Up @@ -140,6 +150,7 @@ class DataItem extends React.Component {
<DataView
data={this.props.value}
path={this.props.path}
immutablesAsJS={this.props.immutablesAsJS}
inspect={this.props.inspect}
showMenu={this.props.showMenu}
readOnly={this.props.readOnly}
Expand Down
16 changes: 15 additions & 1 deletion frontend/PropState.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ class PropState extends React.Component {
var state = this.props.node.get('state');
var context = this.props.node.get('context');
var propsReadOnly = !this.props.node.get('canUpdate');

return (
<div style={styles.container}>
<div>
<input type='checkbox' checked={this.props.immutablesAsJS} onChange={this.props.onToggleImmutablesAsJS.bind(this)} id='immutables-as-js'/>
<label for='immutables-as-js'>Show Immutables as JS</label>
</div>
<div style={styles.header}>
<span style={styles.headerName}>
&lt;{this.props.node.get('name')}&gt;
Expand All @@ -85,6 +88,7 @@ class PropState extends React.Component {
<DataView
path={['props']}
readOnly={propsReadOnly}
immutablesAsJS={this.props.immutablesAsJS}
inspect={this.props.inspect}
showMenu={this.props.showMenu}
key={this.props.id + '-props'}
Expand All @@ -98,6 +102,7 @@ class PropState extends React.Component {
<DataView
data={state}
path={['state']}
immutablesAsJS={this.props.immutablesAsJS}
inspect={this.props.inspect}
showMenu={this.props.showMenu}
key={this.props.id + '-state'}
Expand All @@ -110,6 +115,7 @@ class PropState extends React.Component {
<DataView
data={context}
path={['context']}
immutablesAsJS={this.props.immutablesAsJS}
inspect={this.props.inspect}
showMenu={this.props.showMenu}
key={this.props.id + '-context'}
Expand All @@ -131,15 +137,23 @@ var WrappedPropState = decorate({
return ['selected', store.selected];
},

shouldUpdate() {
return true;
},

props(store) {
var node = store.selected ? store.get(store.selected) : null;
return {
id: store.selected,
immutablesAsJS: store.immutablesAsJS,
node,
canEditTextContent: store.capabilities.editTextContent,
onChangeText(text) {
store.changeTextContent(store.selected, text);
},
onToggleImmutablesAsJS() {
store.toggleImmutablesAsJS(this.props.reload);
},
onChange(path, val) {
if (path[0] === 'props') {
store.setProps(store.selected, path.slice(1), val);
Expand Down
16 changes: 15 additions & 1 deletion frontend/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type ContextMenu = {
* Public actions:
* - scrollToNode(id)
* - changeTextContent(id, text)
* - toggleImmutablesAsJS
* - changeSearch
* - hoverClass
* - selectFirstOfClass
Expand Down Expand Up @@ -88,6 +89,7 @@ class Store extends EventEmitter {

// Public state
contextMenu: ?ContextMenu;
immutablesAsJS: boolean;
hovered: ?ElementID;
isBottomTagSelected: boolean;
roots: List;
Expand All @@ -109,6 +111,7 @@ class Store extends EventEmitter {
// Public state
this.roots = new List();
this.contextMenu = null;
this.immutablesAsJS = false;
this.searchRoots = null;
this.hovered = null;
this.selected = null;
Expand Down Expand Up @@ -162,6 +165,11 @@ class Store extends EventEmitter {
this.emit(id);
}

toggleImmutablesAsJS(cb: () => void): void {
this.immutablesAsJS = !this.immutablesAsJS;
cb();
}

changeSearch(text: string): void {
var needle = text.toLowerCase();
if (needle === this.searchText.toLowerCase()) {
Expand Down Expand Up @@ -363,12 +371,18 @@ class Store extends EventEmitter {
inspect(id: ElementID, path: Array<string>, cb: () => void) {
invariant(path[0] === 'props' || path[0] === 'state' || path[0] === 'context',
'Inspected path must be one of props, state, or context');
this._bridge.inspect(id, path, value => {
this._bridge.inspect(id, path, this.immutablesAsJS, value => {
var base = this.get(id).get(path[0]);
var inspected = path.slice(1).reduce((obj, attr) => obj ? obj[attr] : null, base);
if (inspected) {
if (inspected[consts.immutablesAsJS] !== this.immutablesAsJS) {
Object.getOwnPropertyNames(inspected).forEach(key => {
delete inspected[key];
})
}
assign(inspected, value);
inspected[consts.inspected] = true;
inspected[consts.immutablesAsJS] = this.immutablesAsJS;
}
cb();
});
Expand Down