now it really works!

This commit is contained in:
Joeri Exelmans 2025-05-13 20:56:16 +02:00
parent c31ba88dfd
commit 174bab79e4
5 changed files with 55 additions and 34 deletions

View file

@ -7,7 +7,16 @@ import type { Dynamic, SetStateFn, State2Props } from "./util/extra";
import { useEffect } from "react";
import "./CallBlock.css";
type ResolvedType = Dynamic | Error | undefined;
export class DeepError {
e: Error;
depth: number;
constructor(e, depth) {
this.e = e;
this.depth = depth;
}
};
type ResolvedType = Dynamic | DeepError | undefined;
export interface CallBlockState<
FnState=EditorState,
@ -27,7 +36,7 @@ interface CallBlockProps<
function have(resolved: ResolvedType) {
return resolved && !(resolved instanceof Error);
return resolved && !(resolved instanceof DeepError);
}
function headlessCallBlock({state, setState}: CallBlockProps) {
@ -53,17 +62,16 @@ function headlessCallBlock({state, setState}: CallBlockProps) {
if (!(e instanceof UnifyError) && !(e instanceof NotAFunctionError)) {
throw e;
}
setResolved(() => e as Error); // eval error
setResolved(() => new DeepError(e, 0)); // eval error
}
}
else if (input.resolved instanceof Error) {
else if (input.resolved instanceof DeepError) {
setResolved(() => input.resolved); // bubble up the error
}
else if (fn.resolved instanceof Error) {
// @ts-ignore
else if (fn.resolved instanceof DeepError) {
setResolved(() => {
// @ts-ignore
return Object.assign(fn.resolved, {depth: (fn.resolved.depth || 0) + 1});
return new DeepError(fn.resolved.e, fn.resolved.depth+1);
}); // bubble up the error
}
else {
@ -82,13 +90,8 @@ function headlessCallBlock({state, setState}: CallBlockProps) {
export function CallBlock({ state, setState }: CallBlockProps) {
const {setFn, setInput, onFnCancel, onInputCancel}
= headlessCallBlock({ state, setState });
// @ts-ignore
console.log('depth:', state.resolved?.depth);
return <span className={"functionBlock" + ((state.resolved instanceof Error) ? " unifyError" : "")}>
= headlessCallBlock({ state, setState });
return <span className={"functionBlock" + ((state.resolved instanceof DeepError) ? " unifyError" : "")}>
<FunctionHeader
fn={state.fn}
setFn={setFn}
@ -102,18 +105,17 @@ export function CallBlock({ state, setState }: CallBlockProps) {
input={state.input} setInput={setInput}
onInputCancel={onInputCancel}
depth={0}
// @ts-ignore
errorDepth={state.resolved instanceof Error ? (state.resolved.depth || 0) : -1}
errorDepth={state.resolved instanceof DeepError ? (state.resolved.depth) : -1}
/>
{/* Output (or Error) */}
{ state.resolved instanceof Error && state.resolved.toString()
{ state.resolved instanceof DeepError && state.resolved.e.toString()
|| state.resolved && <><Value dynamic={state.resolved} />&#x2611;</>}
</div>
</div>
</span>;
}
function filterFnInputs(fn: Dynamic|Error|undefined, input: Dynamic|Error|undefined) {
function filterFnInputs(fn: ResolvedType, input: ResolvedType) {
if (!have(fn) || !have(input)) {
return false;
}