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