forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScopes.js
More file actions
182 lines (162 loc) · 4.82 KB
/
Copy pathScopes.js
File metadata and controls
182 lines (162 loc) · 4.82 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* 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 { bindActionCreators } from "redux";
import { connect } from "react-redux";
import actions from "../../actions";
import { createObjectClient } from "../../client/firefox";
import {
getSelectedSource,
getSelectedFrame,
getGeneratedFrameScope,
getOriginalFrameScope,
isPaused as getIsPaused,
getPauseReason
} from "../../selectors";
import { getScopes } from "../../utils/pause/scopes";
import { ObjectInspector } from "devtools-reps";
import type { Pause, Why } from "../../types";
import type { NamedValue } from "../../utils/pause/scopes/types";
import "./Scopes.css";
type Props = {
isPaused: Pause,
selectedFrame: Object,
generatedFrameScopes: Object,
originalFrameScopes: Object | null,
isLoading: boolean,
why: Why
};
type State = {
originalScopes: ?(NamedValue[]),
generatedScopes: ?(NamedValue[]),
showOriginal: boolean
};
class Scopes extends PureComponent<Props, State> {
constructor(props: Props, ...args) {
const {
why,
selectedFrame,
originalFrameScopes,
generatedFrameScopes
} = props;
super(props, ...args);
this.state = {
originalScopes: getScopes(why, selectedFrame, originalFrameScopes),
generatedScopes: getScopes(why, selectedFrame, generatedFrameScopes),
showOriginal: true
};
}
componentWillReceiveProps(nextProps) {
const {
isPaused,
selectedFrame,
originalFrameScopes,
generatedFrameScopes
} = this.props;
const isPausedChanged = isPaused !== nextProps.isPaused;
const selectedFrameChanged = selectedFrame !== nextProps.selectedFrame;
const originalFrameScopesChanged =
originalFrameScopes !== nextProps.originalFrameScopes;
const generatedFrameScopesChanged =
generatedFrameScopes !== nextProps.generatedFrameScopes;
if (
isPausedChanged ||
selectedFrameChanged ||
originalFrameScopesChanged ||
generatedFrameScopesChanged
) {
this.setState({
originalScopes: getScopes(
nextProps.why,
nextProps.selectedFrame,
nextProps.originalFrameScopes
),
generatedScopes: getScopes(
nextProps.why,
nextProps.selectedFrame,
nextProps.generatedFrameScopes
)
});
}
}
render() {
const { isPaused, isLoading } = this.props;
const { originalScopes, generatedScopes, showOriginal } = this.state;
const scopes = (showOriginal && originalScopes) || generatedScopes;
if (scopes && !isLoading) {
return (
<div className="pane scopes-list">
<ObjectInspector
roots={scopes}
autoExpandAll={false}
autoExpandDepth={1}
disableWrap={true}
disabledFocus={true}
dimTopLevelWindow={true}
createObjectClient={grip => createObjectClient(grip)}
/>
{originalScopes ? (
<div className="scope-type-toggle">
<a
href=""
onClick={e => {
e.preventDefault();
this.setState({ showOriginal: !showOriginal });
}}
>
{showOriginal
? L10N.getStr("scopes.toggleToGenerated")
: L10N.getStr("scopes.toggleToOriginal")}
</a>
</div>
) : null}
</div>
);
}
let stateText = L10N.getStr("scopes.notPaused");
if (isPaused) {
if (isLoading) {
stateText = L10N.getStr("loadingText");
} else {
stateText = L10N.getStr("scopes.notAvailable");
}
}
return (
<div className="pane scopes-list">
<div className="pane-info">{stateText}</div>
</div>
);
}
}
export default connect(
state => {
const selectedFrame = getSelectedFrame(state);
const selectedSource = getSelectedSource(state);
const {
scope: originalFrameScopes,
pending: originalPending
} = getOriginalFrameScope(
state,
selectedSource && selectedSource.get("id"),
selectedFrame && selectedFrame.id
) || { scope: null, pending: false };
const {
scope: generatedFrameScopes,
pending: generatedPending
} = getGeneratedFrameScope(state, selectedFrame && selectedFrame.id) || {
scope: null,
pending: false
};
return {
selectedFrame,
isPaused: getIsPaused(state),
isLoading: generatedPending || originalPending,
why: getPauseReason(state),
originalFrameScopes,
generatedFrameScopes
};
},
dispatch => bindActionCreators(actions, dispatch)
)(Scopes);