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