forked from facebook/react-devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer.js
More file actions
51 lines (44 loc) · 1.25 KB
/
container.js
File metadata and controls
51 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
'use strict';
var React = require('react');
var globalHook = require('../../backend/GlobalHook');
window.React = React;
var Panel = require('../../frontend/Panel');
var target: Object = document.getElementById('target');
function inject(src, done) {
var script = target.contentDocument.createElement('script');
script.src = src;
script.onload = done;
target.contentDocument.body.appendChild(script);
}
var win = target.contentWindow;
globalHook(win);
var config = {
alreadyFoundReact: true,
inject(done) {
inject('./build/backend.js', () => {
var wall = {
listen(fn) {
win.parent.addEventListener('message', evt => fn(evt.data));
},
send(data) {
win.postMessage(data, '*');
},
};
done(wall);
});
},
};
inject('../../test/example/build/target.js', () => {
var node = document.getElementById('container');
React.render(<Panel {...config} />, node);
});