greatly simplify state + cleanup code

This commit is contained in:
Joeri Exelmans 2025-05-14 08:09:35 +02:00
parent 2d0deca127
commit 5964510036
11 changed files with 268 additions and 321 deletions

View file

@ -1,18 +1,12 @@
import { apply, Int, trie } from "dope2";
import type { EditorState } from "./Editor";
import { extendedEnv } from "./EnvContext";
export const initialEditorState: EditorState = {
kind: "input",
text: "",
resolved: undefined,
value: { kind: "text" },
focus: true,
};
const listPush = trie.get(extendedEnv.name2dyn)("list.push");
const listEmptyList = trie.get(extendedEnv.name2dyn)("list.emptyList");
const fourtyTwo = { i: 42n, t: Int };
export const nonEmptyEditorState: EditorState = {
kind: "call",
fn: {
@ -20,33 +14,24 @@ export const nonEmptyEditorState: EditorState = {
fn: {
kind: "input",
text: "list.push",
resolved: listPush,
value: { kind: "name" },
focus: false,
},
input: {
kind: "input",
text: "list.emptyList",
resolved: listEmptyList,
value: { kind: "name" },
focus: false,
},
resolved: apply(listEmptyList)(listPush),
// focus: ,
},
input: {
kind: "input",
text: "42",
resolved: fourtyTwo,
value: { kind: "literal", type: "Int" },
focus: false,
},
// resolved: apply(fourtyTwo)(apply(listEmptyList)(listPush)),
resolved: undefined,
};
const functionWith4Params = trie.get(extendedEnv.name2dyn)("functionWith4Params");
const fourtyThree = { i: 43n, t: Int };
const fourtyFour = { i: 44n, t: Int };
const fourtyFive = { i: 45n, t: Int };
export const tripleFunctionCallEditorState: EditorState = {
kind: "call",
fn: {
@ -58,38 +43,34 @@ export const tripleFunctionCallEditorState: EditorState = {
fn: {
kind: "input",
text: "functionWith4Params",
resolved: functionWith4Params,
value: { kind: "name" },
focus: false,
},
input: {
kind: "input",
text: "42",
resolved: fourtyTwo,
value: { kind: "literal", type: "Int" },
focus: false,
},
resolved: apply(fourtyTwo)(functionWith4Params),
},
input: {
kind: "input",
text: "43",
resolved: fourtyThree,
value: { kind: "literal", type: "Int" },
focus: false,
},
resolved: apply(fourtyThree)(apply(fourtyTwo)(functionWith4Params)),
},
input: {
kind: "input",
text: "44",
resolved: fourtyFour,
value: { kind: "literal", type: "Int" },
focus: false,
},
resolved: apply(fourtyFour)(apply(fourtyThree)(apply(fourtyTwo)(functionWith4Params))),
},
input: {
kind: "input",
text: "45",
resolved: fourtyFive,
value: { kind: "literal", type: "Int" },
focus: false,
},
resolved: apply(fourtyFive)(apply(fourtyFour)(apply(fourtyThree)(apply(fourtyTwo)(functionWith4Params)))),
};