From 9afaa41fbba0970687a30ff27de484cbebcba60d Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Mon, 12 May 2025 17:18:57 +0200 Subject: [PATCH] implement nested handlers in call block --- src/App.tsx | 5 ++--- src/CallBlock.tsx | 52 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index f4067cb..f53f69e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,3 @@ -// import { useState } from 'react' import { useEffect, useState } from 'react'; import './App.css' import { Editor, initialEditorState, type EditorState } from './Editor' @@ -82,9 +81,9 @@ const tripleFunctionCallEditorState: EditorState = { } export function App() { - const [history, setHistory] = useState([initialEditorState]); + // const [history, setHistory] = useState([initialEditorState]); // const [history, setHistory] = useState([nonEmptyEditorState]); - // const [history, setHistory] = useState([tripleFunctionCallEditorState]); + const [history, setHistory] = useState([tripleFunctionCallEditorState]); const [future, setFuture] = useState([]); diff --git a/src/CallBlock.tsx b/src/CallBlock.tsx index ae5116a..d2034a0 100644 --- a/src/CallBlock.tsx +++ b/src/CallBlock.tsx @@ -1,12 +1,12 @@ -import { apply, getType, getInst, assignFn, UnifyError } from "dope2"; -import type { Dynamic, State2Props } from "./util/extra"; +import { useState } from "react"; + +import { apply, UnifyError } from "dope2"; + import { Editor, type EditorState } from "./Editor"; +import { Value } from "./Value"; +import type { Dynamic, State2Props } from "./util/extra"; import "./CallBlock.css"; -import { useEffect, useState } from "react"; -import { Type } from "./Type"; -import { Value } from "./Value"; -import { focusPrevElement } from "./util/dom_trickery"; export interface CallBlockState< FnState=EditorState, @@ -110,11 +110,17 @@ export function CallBlock({ state, setState, onResolve }: CallBlockProps) { const {unifyError, setFn, setInput, onFnResolve, onInputResolve, onFnCancel, onInputCancel} = headlessCallBlock({ state, setState, onResolve }); return - +
{/* Sequence of input parameters */} - {/* Output (or Error) */} @@ -125,25 +131,39 @@ export function CallBlock({ state, setState, onResolve }: CallBlockProps) { ; } -function FunctionHeader({ fn }) { +function FunctionHeader({ fn, setFn, onFnResolve }) { if (fn.kind === "call") { // if the function we're calling is itself the result of a function call, // then we are anonymous, and so we don't draw a function name // recurse: - return ; + const { + onFnResolve : onFnFnResolve + } = headlessCallBlock({state: fn, setState: setFn, onResolve: onFnResolve}); + + return setFn({...fn, fn: fnFn})} + onFnResolve={onFnFnResolve} />; } else { // end of recursion - draw function name return
𝑓𝑛  - {/*todo*/}} - onResolve={() => {}} onCancel={() => {/*todo*/}}/> + {/*todo*/}}/>
; } } -function InputParams({ fn, input, setInput, onInputResolve, onInputCancel }) { +function InputParams({ fn, setFn, input, setInput, onFnResolve, onInputResolve, onInputCancel }) { + const { + onInputResolve: onFnInputResolve, + onFnResolve : onFnFnResolve + } = headlessCallBlock({state: fn, setState: setFn, onResolve: onFnResolve}); return
{(fn.kind === "call") && // if the function we're calling is itself the result of a function call, @@ -152,9 +172,11 @@ function InputParams({ fn, input, setInput, onInputResolve, onInputCancel }) { // Input(s) of the function we're calling: setFn({...fn, fn: fnFn})} input={fn.input} - setInput={() => {/*todo*/}} - onInputResolve={() => {/*todo*/}} + setInput={fnInput => setFn({...fn, input: fnInput})} + onFnResolve={onFnFnResolve} + onInputResolve={onFnInputResolve} onInputCancel={() => {/*todo*/}}/> }