refactor a bit more
This commit is contained in:
parent
230916ceb1
commit
fdbf43a4e9
11 changed files with 79 additions and 90 deletions
|
|
@ -8,6 +8,8 @@ import { Value } from "./Value";
|
|||
|
||||
import "./CallBlock.css";
|
||||
import { initialEditorState } from "./configurations";
|
||||
import { CallContext } from "./CallContext";
|
||||
import { getActions } from "./actions";
|
||||
|
||||
export interface CallBlockState {
|
||||
kind: "call";
|
||||
|
|
@ -55,31 +57,26 @@ function nestedInputProperties({state, setState, suggestionPriority}: CallBlockP
|
|||
export function CallBlock(props: CallBlockProps) {
|
||||
const env = useContext(EnvContext);
|
||||
const globalContext = useContext(GlobalContext);
|
||||
const addParam = (s: ExprBlockState) => {
|
||||
props.setState(state => ({
|
||||
kind: "call",
|
||||
fn: removeFocus(state),
|
||||
input: s,
|
||||
}));
|
||||
globalContext?.doHighlight.call();
|
||||
};
|
||||
const addParam = getActions(globalContext, props.setState).c;
|
||||
const [resolved] = evalEditorBlock(props.state, env);
|
||||
return <span className={"functionBlock" + ((resolved.kind === "error") ? " unifyError" : "")}>
|
||||
<FunctionHeader {...props} addParam={addParam} />
|
||||
<div className="functionParams">
|
||||
<div className="outputParam">
|
||||
{/* Sequence of input parameters */}
|
||||
<InputParams
|
||||
{...props}
|
||||
depth={0}
|
||||
errorDepth={(resolved.kind === "error") ? (resolved.depth) : -1}
|
||||
addParam={addParam}
|
||||
/>
|
||||
{ (resolved.kind === "error") && resolved.e.toString()
|
||||
|| (resolved.kind === "value") && <Value dynamic={resolved} />
|
||||
|| "unknown" }
|
||||
<CallContext value={{addParam}}>
|
||||
<FunctionHeader {...props} addParam={addParam} />
|
||||
<div className="functionParams">
|
||||
<div className="outputParam">
|
||||
{/* Sequence of input parameters */}
|
||||
<InputParams
|
||||
{...props}
|
||||
depth={0}
|
||||
errorDepth={(resolved.kind === "error") ? (resolved.depth) : -1}
|
||||
addParam={addParam}
|
||||
/>
|
||||
{ (resolved.kind === "error") && resolved.e.toString()
|
||||
|| (resolved.kind === "value") && <Value dynamic={resolved} />
|
||||
|| "unknown" }
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CallContext>
|
||||
</span>;
|
||||
}
|
||||
|
||||
|
|
@ -102,12 +99,12 @@ function FunctionHeader(props) {
|
|||
// end of recursion - draw function name
|
||||
return <span className="functionName">
|
||||
𝑓𝑛
|
||||
<ExprBlock {...nestedProperties} addParam={props.addParam} />
|
||||
<ExprBlock {...nestedProperties} />
|
||||
</span>;
|
||||
}
|
||||
}
|
||||
|
||||
function InputParams({ depth, errorDepth, addParam, ...rest }) {
|
||||
function InputParams({ depth, errorDepth, ...rest }) {
|
||||
const env = useContext(EnvContext);
|
||||
const globalContext = useContext(GlobalContext);
|
||||
const isOffending = depth === errorDepth;
|
||||
|
|
@ -118,12 +115,10 @@ function InputParams({ depth, errorDepth, addParam, ...rest }) {
|
|||
{...nestedFnProperties(rest as CallBlockProps, env)}
|
||||
depth={depth+1}
|
||||
errorDepth={errorDepth}
|
||||
addParam={addParam}
|
||||
/>}
|
||||
{/* Our own input param */}
|
||||
<ExprBlock
|
||||
{...nestedInputProperties(rest as CallBlockProps, env)}
|
||||
addParam={addParam}
|
||||
/>
|
||||
</div>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue