forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreviewFunction.js
More file actions
63 lines (50 loc) · 1.6 KB
/
Copy pathPreviewFunction.js
File metadata and controls
63 lines (50 loc) · 1.6 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
/* 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, { Component } from "react";
import { times, zip, flatten } from "lodash";
import { simplifyDisplayName } from "../../utils/pause/frames";
import "./PreviewFunction.css";
type FunctionType = {
name: string,
displayName?: string,
userDisplayName?: string,
parameterNames?: string[]
};
type Props = { func: FunctionType };
function getFunctionName(func: FunctionType) {
const name = func.userDisplayName || func.displayName || func.name;
return simplifyDisplayName(name);
}
export default class PreviewFunction extends Component<Props> {
renderFunctionName(func: FunctionType) {
const name = getFunctionName(func);
return <span className="function-name">{name}</span>;
}
renderParams(func: FunctionType) {
const { parameterNames = [] } = func;
const params = parameterNames.filter(i => i).map(param => (
<span className="param" key={param}>
{param}
</span>
));
const commas = times(params.length - 1).map((_, i) => (
<span className="delimiter" key={i}>
{", "}
</span>
));
// $FlowIgnore
return flatten(zip(params, commas));
}
render() {
return (
<span className="function-signature">
{this.renderFunctionName(this.props.func)}
<span className="paren">(</span>
{this.renderParams(this.props.func)}
<span className="paren">)</span>
</span>
);
}
}