From f75d0641b420730498eeab21db1854b3093bf2f1 Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Mon, 12 May 2025 15:50:13 +0200 Subject: [PATCH] set default editor state to something non-empty --- src/App.tsx | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/src/App.tsx b/src/App.tsx index 031f3b6..9c70a72 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,9 +2,89 @@ import { useEffect, useState } from 'react'; import './App.css' import { Editor, initialEditorState, type EditorState } from './Editor' +import { trie, apply, Int } from "dope2"; + +const listPush = trie.get(initialEditorState.env.name2dyn)("list.push"); +const listEmptyList = trie.get(initialEditorState.env.name2dyn)("list.emptyList"); +const fourtyTwo = {i: 42n, t: Int}; + +const nonEmptyEditorState: EditorState = { + kind: "call", + env: initialEditorState.env, + fn: { + kind: "call", + env: initialEditorState.env, + fn: { + kind: "input", + env: initialEditorState.env, + text: "list.push", + resolved: listPush, + }, + input: { + kind: "input", + env: initialEditorState.env, + text: "list.emptyList", + resolved: listEmptyList, + }, + resolved: apply(listEmptyList)(listPush), + }, + input: { + kind: "input", + env: initialEditorState.env, + text: "42", + resolved: fourtyTwo, + }, + resolved: apply(fourtyTwo)(apply(listEmptyList)(listPush)), +}; + +const functionWith3Params = trie.get(initialEditorState.env.name2dyn)("functionWith3Params"); +const fourtyThree = {i: 43n, t: Int}; +const fourtyFour = {i: 44n, t: Int}; + +const tripleFunctionCallEditorState: EditorState = { + kind: "call", + env: initialEditorState.env, + fn: { + kind: "call", + env: initialEditorState.env, + fn: { + kind: "call", + env: initialEditorState.env, + fn: { + kind: "input", + env: initialEditorState.env, + text: "functionWith3Params", + resolved: functionWith3Params, + }, + input: { + kind: "input", + env: initialEditorState.env, + text: "42", + resolved: fourtyTwo, + }, + resolved: apply(fourtyTwo)(functionWith3Params), + }, + input: { + kind: "input", + env: initialEditorState.env, + text: "43", + resolved: fourtyThree, + }, + resolved: apply(fourtyThree)(apply(fourtyTwo)(functionWith3Params)), + }, + input: { + kind: "input", + env: initialEditorState.env, + text: "44", + resolved: fourtyFour, + }, + resolved: apply(fourtyFour)(apply(fourtyThree)(apply(fourtyTwo)(functionWith3Params))), +} export function App() { - const [state, setState] = useState(initialEditorState); + // const [state, setState] = useState(initialEditorState); + // const [state, setState] = useState(nonEmptyEditorState); + const [state, setState] = useState(tripleFunctionCallEditorState); useEffect(() => { window['APP_STATE'] = state;