forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrameworkComponent.js
More file actions
97 lines (80 loc) · 2.73 KB
/
Copy pathFrameworkComponent.js
File metadata and controls
97 lines (80 loc) · 2.73 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// @flow
import React, { PureComponent } from "react";
import { connect } from "react-redux";
import actions from "../../actions";
import { createObjectClient } from "../../client/firefox";
import { getSelectedFrame, getAllPopupObjectProperties } from "../../selectors";
import { ObjectInspector, ObjectInspectorUtils } from "devtools-reps";
import { isReactComponent } from "../../utils/preview";
import type { Frame } from "../../types";
const { createNode, getChildren } = ObjectInspectorUtils.node;
const { loadItemProperties } = ObjectInspectorUtils.loadProperties;
type Props = {
selectedFrame: Frame,
popupObjectProperties: Object,
setPopupObjectProperties: (Object, Object) => void
};
class FrameworkComponent extends PureComponent<Props> {
async componentWillMount() {
const expression = "this;";
const { selectedFrame, setPopupObjectProperties } = this.props;
const value = selectedFrame.this;
const root = createNode({ name: expression, contents: { value } });
const properties = await loadItemProperties(root, createObjectClient);
if (properties) {
setPopupObjectProperties(value, properties);
}
}
renderReactComponent() {
const { selectedFrame, popupObjectProperties } = this.props;
const expression = "this;";
const value = selectedFrame.this;
const root = {
name: expression,
path: expression,
contents: { value }
};
const loadedRootProperties = popupObjectProperties[value.actor];
if (!loadedRootProperties) {
return null;
}
let roots = getChildren({
item: root,
loadedProperties: new Map([[root.path, loadedRootProperties]])
});
roots = roots.filter(r => ["state", "props"].includes(r.name));
return (
<div className="pane framework-component">
<ObjectInspector
roots={roots}
autoExpandAll={false}
autoExpandDepth={0}
disableWrap={true}
focusable={false}
dimTopLevelWindow={true}
createObjectClient={grip => createObjectClient(grip)}
/>
</div>
);
}
render() {
const { selectedFrame } = this.props;
if (selectedFrame && isReactComponent(selectedFrame.this)) {
return this.renderReactComponent();
}
return null;
}
}
const mapStateToProps = state => ({
selectedFrame: getSelectedFrame(state),
popupObjectProperties: getAllPopupObjectProperties(state)
});
export default connect(
mapStateToProps,
{
setPopupObjectProperties: actions.setPopupObjectProperties
}
)(FrameworkComponent);