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

Commit fc987c8

Browse files
committed
trying out new panel in plain shell
1 parent a8e7126 commit fc987c8

File tree

5 files changed

+137
-23
lines changed

5 files changed

+137
-23
lines changed

frontend/invariant.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright 2013-2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
*/
10+
'use strict';
11+
12+
/**
13+
* Use invariant() to assert state which your program assumes to be true.
14+
*
15+
* Provide sprintf-style format (only %s is supported) and arguments
16+
* to provide information about what broke and what you were
17+
* expecting.
18+
*
19+
* The invariant message will be stripped in production, but the invariant
20+
* will remain to ensure logic does not differ in production.
21+
*/
22+
23+
var invariant = function(condition, format, a, b, c, d, e, f) {
24+
if (__DEV__) {
25+
if (format === undefined) {
26+
throw new Error('invariant requires an error message argument');
27+
}
28+
}
29+
30+
if (!condition) {
31+
var error;
32+
if (format === undefined) {
33+
error = new Error(
34+
'Minified exception occurred; use the non-minified dev environment ' +
35+
'for the full error message and additional helpful warnings.'
36+
);
37+
} else {
38+
var args = [a, b, c, d, e, f];
39+
var argIndex = 0;
40+
error = new Error(
41+
'Invariant Violation: ' +
42+
format.replace(/%s/g, function() { return args[argIndex++]; })
43+
);
44+
}
45+
46+
error.framesToPop = 1; // we don't care about invariant's own frame
47+
throw error;
48+
}
49+
};
50+
51+
module.exports = invariant;
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111
'use strict';
1212

1313
var React = require('react');
14-
var Bridge = require('../../../agent/Bridge');
15-
var Container = require('../../../frontend/Container');
16-
var NativeStyler = require('../../../plugins/ReactNativeStyle/ReactNativeStyle.js');
17-
var Store = require('../../../frontend/Store');
18-
var keyboardNav = require('../../../frontend/keyboardNav');
14+
var Container = require('./Container');
15+
var Store = require('./Store');
16+
var keyboardNav = require('./keyboardNav');
17+
var invariant = require('./invariant');
1918

20-
var consts = require('../../../agent/consts');
19+
var Bridge = require('../agent/Bridge');
20+
var NativeStyler = require('../plugins/ReactNativeStyle/ReactNativeStyle.js');
2121

22-
import type {DOMEvent} from '../../../frontend/types';
22+
var consts = require('../agent/consts');
23+
24+
import type {DOMEvent} from './types';
2325

2426
type Props = {
2527
alreadyFoundReact: boolean,
@@ -100,10 +102,12 @@ class Panel extends React.Component {
100102
if (!this._bridge || (!id && !this._store.selected)) {
101103
return;
102104
}
105+
invariant(this.props.selectElement, 'cannot send selection if props.selectElement is not defined');
103106
this.props.selectElement(id || this._store.selected, this._bridge);
104107
}
105108

106109
inspectComponent(vbl: string) {
110+
invariant(this.props.showComponentSource, 'cannot inspect component if props.showComponentSource is not supplied');
107111
this.props.showComponentSource(vbl || '$r');
108112
}
109113

@@ -113,6 +117,7 @@ class Panel extends React.Component {
113117
}
114118
this._bridge.send('putSelectedInstance', id);
115119
setTimeout(() => {
120+
invariant(this.props.showComponentSource, 'cannot view source if props.showComponentSource is not supplied');
116121
this.props.showComponentSource('__REACT_DEVTOOLS_GLOBAL_HOOK__.$inst');
117122
}, 100);
118123
}
@@ -137,7 +142,6 @@ class Panel extends React.Component {
137142
this._teardownWall = teardown;
138143

139144
this._bridge = new Bridge();
140-
// $FlowFixMe flow thinks `this._bridge` might be null
141145
this._bridge.attach(wall);
142146

143147
// xx FlowFixMe this._bridge is not null
@@ -193,17 +197,19 @@ class Panel extends React.Component {
193197
}
194198
return (
195199
<Container
196-
reload={this.reload.bind(this)}
200+
reload={this.props.reload && this.reload.bind(this)}
197201
menuItems={{
198202
attr: (id, node, val, path, name) => {
199203
if (!val || node.get('nodeType') !== 'Composite' || val[consts.type] !== 'function') {
200204
return;
201205
}
202206
return [this.props.showAttrSource && {
203207
title: 'Show Source',
208+
// $FlowFixMe showAttrSource is provided
204209
action: () => this.props.showAttrSource(path),
205210
}, this.props.executeFn && {
206211
title: 'Execute function',
212+
// $FlowFixMe executeFn is provided
207213
action: () => this.props.executeFn(path),
208214
}];
209215
},

shells/chrome/src/panel.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var config = {
5252
chrome.devtools.network.onNavigated.removeListener(reload);
5353
};
5454
},
55-
getNewSelectiong(bridge) {
55+
getNewSelection(bridge) {
5656
chrome.devtools.inspectedWindow.eval('window.__REACT_DEVTOOLS_GLOBAL_HOOK__.$0 = $0');
5757
bridge.send('checkSelection');
5858
},
@@ -117,10 +117,9 @@ var config = {
117117
},
118118
};
119119

120-
121120
var globalHook = require('../../../backend/GlobalHook');
122121
globalHook(window);
123-
var Panel = require('./magic');
122+
var Panel = require('../../../frontend/magic');
124123
var React = require('react');
125124

126125
var node = document.getElementById('container');
@@ -134,6 +133,3 @@ function reload() {
134133
}
135134

136135
React.render(<Panel alreadyFoundReact={true} {...config} />, node);
137-
138-
139-

shells/plain/container.js

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,55 @@
1313
var Harness = require('./Harness');
1414
var Container = require('../../frontend/Container');
1515
var React = require('react');
16+
var globalHook = require('../../backend/GlobalHook');
1617

1718
window.React = React;
1819

19-
var node = document.createElement('div');
20-
document.body.appendChild(node);
21-
React.render(
22-
<Harness backendSrc="./build/backend.js" targetSrc="../../test/example/build/target.js">
23-
<Container/>
24-
</Harness>,
25-
node
26-
);
20+
var Panel = require('../../frontend/magic');
21+
22+
var target = document.getElementById('target');
23+
function inject(src, done) {
24+
var script = target.contentDocument.createElement('script');
25+
script.src = src;
26+
script.onload = done;
27+
target.contentDocument.body.appendChild(script);
28+
// script.parentNode.removeChild(script);
29+
}
30+
31+
var win = target.contentWindow;
32+
globalHook(win);
33+
34+
var config = {
35+
alreadyFoundReact: true,
36+
reload: null,
37+
checkForReact: null,
38+
reloadSubscribe: null,
39+
getNewSelection: null,
40+
selectElement: null,
41+
showComponentSource: null,
42+
showAttrSource: null,
43+
executeFn: null,
44+
inject(done) {
45+
inject('./build/backend.js', () => {
46+
var wall = {
47+
listen(fn) {
48+
win.parent.addEventListener('message', evt => fn(evt.data));
49+
},
50+
send(data) {
51+
win.postMessage(data, '*');
52+
},
53+
};
54+
done(wall, () => {});
55+
});
56+
},
57+
};
58+
59+
inject('../../test/example/build/target.js', () => {
60+
var node = document.getElementById('container');
61+
React.render(
62+
<Panel {...config} />,
63+
node
64+
);
65+
});
2766

2867

shells/plain/index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,30 @@
33
<head>
44
<meta charset="utf8">
55
<title>Container Example</title>
6+
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
7+
<style>
8+
#target {
9+
flex: 1;
10+
border: none;
11+
}
12+
#container {
13+
display: flex;
14+
height: 500px;
15+
}
16+
body {
17+
display: flex;
18+
flex-direction: column;
19+
position: absolute;
20+
top: 0;
21+
left: 0;
22+
right: 0;
23+
bottom: 0;
24+
}
25+
</style>
626
</head>
727
<body>
28+
<iframe id="target"></iframe>
29+
<div id="container"></div>
830
<script src="build/container.js"></script>
931
</body>
1032
</html>

0 commit comments

Comments
 (0)