Refactored if statement into switch
This commit is contained in:
parent
69fb8be1f1
commit
8a29205247
|
@ -56,13 +56,14 @@ const SquiggleItem: React.FC<SquiggleItemProps> = ({
|
|||
width,
|
||||
height,
|
||||
}: SquiggleItemProps) => {
|
||||
if (expression.tag === "number") {
|
||||
switch (expression.tag) {
|
||||
case "number":
|
||||
return (
|
||||
<VariableBox heading="Number">
|
||||
<NumberShower precision={3} number={expression.value} />
|
||||
</VariableBox>
|
||||
);
|
||||
} else if (expression.tag === "distribution") {
|
||||
case "distribution": {
|
||||
let distType = expression.value.type();
|
||||
return (
|
||||
<VariableBox heading={`Distribution (${distType})`}>
|
||||
|
@ -80,21 +81,22 @@ const SquiggleItem: React.FC<SquiggleItemProps> = ({
|
|||
/>
|
||||
</VariableBox>
|
||||
);
|
||||
} else if (expression.tag === "string") {
|
||||
}
|
||||
case "string":
|
||||
return (
|
||||
<VariableBox heading="String">{`"${expression.value}"`}</VariableBox>
|
||||
);
|
||||
} else if (expression.tag === "boolean") {
|
||||
case "boolean":
|
||||
return (
|
||||
<VariableBox heading="Boolean">
|
||||
{expression.value == true ? "True" : "False"}
|
||||
{expression.value.toString()}
|
||||
</VariableBox>
|
||||
);
|
||||
} else if (expression.tag === "symbol") {
|
||||
case "symbol":
|
||||
return <VariableBox heading="Symbol">{expression.value}</VariableBox>;
|
||||
} else if (expression.tag === "call") {
|
||||
case "call":
|
||||
return <VariableBox heading="Call">{expression.value}</VariableBox>;
|
||||
} else if (expression.tag === "array") {
|
||||
case "array":
|
||||
return (
|
||||
<VariableBox heading="Array">
|
||||
{expression.value.map((r) => (
|
||||
|
@ -102,10 +104,10 @@ const SquiggleItem: React.FC<SquiggleItemProps> = ({
|
|||
))}
|
||||
</VariableBox>
|
||||
);
|
||||
} else {
|
||||
default:
|
||||
return (
|
||||
<ErrorBox heading="No Viewer">
|
||||
{"We don't currently have a viewer for record types."}
|
||||
{"We don't currently have a working viewer for record types."}
|
||||
</ErrorBox>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user