more progress
This commit is contained in:
parent
2b0d8bc2c6
commit
ebae0afc81
7 changed files with 94 additions and 21 deletions
|
|
@ -1,9 +1,9 @@
|
|||
import { apply, getType, getInst } from "dope2";
|
||||
import { apply, getType, getInst, assignFn, UnifyError } from "dope2";
|
||||
import type { Dynamic, State2Props } from "./util/extra";
|
||||
import { Editor, type EditorState } from "./Editor";
|
||||
|
||||
import "./CallBlock.css";
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Type } from "./Type";
|
||||
import { Value } from "./Value";
|
||||
import { focusPrevElement } from "./util/dom_trickery";
|
||||
|
|
@ -22,6 +22,7 @@ interface CallBlockProps extends State2Props<CallBlockState> {
|
|||
}
|
||||
|
||||
export function CallBlock({ state: {kind, env, fn, input, resolved, rollback }, setState, onResolve }: CallBlockProps) {
|
||||
const [unifyError, setUnifyError] = useState<UnifyError | undefined>(undefined);
|
||||
const setResolved = (resolved?: Dynamic) => {
|
||||
setState({kind, env, fn, input, resolved, rollback});
|
||||
}
|
||||
|
|
@ -35,9 +36,16 @@ export function CallBlock({ state: {kind, env, fn, input, resolved, rollback },
|
|||
onResolve({
|
||||
kind, env, fn, input, resolved: outputResolved, rollback
|
||||
});
|
||||
setUnifyError(undefined);
|
||||
}
|
||||
catch (e) {
|
||||
console.log('makeTheCall:', e);
|
||||
if (!(e instanceof UnifyError)) {
|
||||
throw e;
|
||||
}
|
||||
setUnifyError(e);
|
||||
onResolve({
|
||||
kind, env, fn, input, resolved: undefined, rollback
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +92,21 @@ export function CallBlock({ state: {kind, env, fn, input, resolved, rollback },
|
|||
}
|
||||
}
|
||||
|
||||
return <span className="functionBlock">
|
||||
const filterCompatibleInputs = ([_name, dynamic]: [string, Dynamic]) => {
|
||||
if (fn.resolved) {
|
||||
try {
|
||||
assignFn(getType(fn.resolved), getType(dynamic));
|
||||
} catch (e) {
|
||||
if (!(e instanceof UnifyError)) {
|
||||
throw e;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return <span className={"functionBlock" + (unifyError ? " unifyError" : "")}>
|
||||
<div className="functionName">
|
||||
𝑓𝑛
|
||||
<Editor state={fn} setState={setFn}
|
||||
|
|
@ -98,6 +120,10 @@ export function CallBlock({ state: {kind, env, fn, input, resolved, rollback },
|
|||
{ resolved
|
||||
? <Value dynamic={resolved} />
|
||||
: <></> }
|
||||
{ unifyError
|
||||
? <>{unifyError.toString()}</>
|
||||
: <></>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</span>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue