/* 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 . */ // @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 { renderFunctionName(func: FunctionType) { const name = getFunctionName(func); return {name}; } renderParams(func: FunctionType) { const { parameterNames = [] } = func; const params = parameterNames.filter(i => i).map(param => ( {param} )); const commas = times(params.length - 1).map((_, i) => ( {", "} )); // $FlowIgnore return flatten(zip(params, commas)); } render() { return ( {this.renderFunctionName(this.props.func)} ( {this.renderParams(this.props.func)} ) ); } }