forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallSite.js
More file actions
95 lines (77 loc) · 2.05 KB
/
Copy pathCallSite.js
File metadata and controls
95 lines (77 loc) · 2.05 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
/* 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 { Component } from "react";
import { markText, toEditorRange } from "../../utils/editor";
require("./CallSite.css");
type MarkerType = {
clear: Function
};
type Props = {
callSite: Object,
editor: Object,
source: Object,
breakpoint: Object,
showCallSite: boolean
};
export default class CallSite extends Component<Props> {
addCallSite: Function;
marker: ?MarkerType;
constructor() {
super();
this.marker = undefined;
}
addCallSite = (nextProps: ?Props) => {
const { editor, callSite, breakpoint, source } = nextProps || this.props;
const className = !breakpoint ? "call-site" : "call-site-bp";
const sourceId = source.get("id");
const editorRange = toEditorRange(sourceId, callSite.location);
this.marker = markText(editor, className, editorRange);
};
clearCallSite = () => {
if (this.marker) {
this.marker.clear();
this.marker = null;
}
};
shouldComponentUpdate(nextProps: Props) {
return this.props.editor !== nextProps.editor;
}
componentDidMount() {
const { breakpoint, showCallSite } = this.props;
if (!breakpoint && !showCallSite) {
return;
}
this.addCallSite();
}
componentWillReceiveProps(nextProps: Props) {
const { breakpoint, showCallSite } = this.props;
if (nextProps.breakpoint !== breakpoint) {
if (this.marker) {
this.clearCallSite();
}
if (nextProps.showCallSite) {
this.addCallSite(nextProps);
}
}
if (nextProps.showCallSite !== showCallSite) {
if (nextProps.showCallSite) {
if (!this.marker) {
this.addCallSite();
}
} else if (!nextProps.breakpoint) {
this.clearCallSite();
}
}
}
componentWillUnmount() {
if (!this.marker) {
return;
}
this.marker.clear();
}
render() {
return null;
}
}