From 7220a12aed70e1063f9b98752e09f17f8f90c596 Mon Sep 17 00:00:00 2001 From: Neta London Date: Wed, 31 Jul 2024 14:04:38 +0300 Subject: [PATCH] Move Action change to another PR --- components/src/inline_edit.tsx | 3 +-- components/src/stores/asm.store.ts | 3 +-- components/src/stores/base.context.ts | 3 +-- components/src/stores/chip.store.ts | 2 +- components/src/stores/compiler.store.ts | 3 +-- components/src/stores/cpu.store.ts | 3 +-- components/src/stores/vm.store.ts | 5 ++--- simulator/src/test/tst.ts | 4 ++-- web/src/pico/inline_edit.tsx | 3 +-- web/src/shell/Monaco.tsx | 3 +-- web/src/shell/editor.tsx | 5 ++--- 11 files changed, 14 insertions(+), 23 deletions(-) diff --git a/components/src/inline_edit.tsx b/components/src/inline_edit.tsx index 7f28ed70..88ce9f2e 100644 --- a/components/src/inline_edit.tsx +++ b/components/src/inline_edit.tsx @@ -1,7 +1,6 @@ import { width } from "@davidsouther/jiffies/lib/esm/dom/css/sizing.js"; import { useCallback, useState } from "react"; import { useStateInitializer } from "./react.js"; -import { Action } from "@nand2tetris/simulator/types.js"; const Mode = { VIEW: 0, EDIT: 1 }; @@ -9,7 +8,7 @@ export const InlineEdit = (props: { mode?: keyof typeof Mode; value: string; highlight: boolean; - onChange: Action; + onChange: (value: string) => void; onFocus?: () => void; }) => { const [mode, setMode] = useState(props.mode ?? Mode.VIEW); diff --git a/components/src/stores/asm.store.ts b/components/src/stores/asm.store.ts index 64237f70..28b8f38d 100644 --- a/components/src/stores/asm.store.ts +++ b/components/src/stores/asm.store.ts @@ -20,7 +20,6 @@ import { CompilationError, Span, } from "@nand2tetris/simulator/languages/base.js"; -import { Action } from "@nand2tetris/simulator/types.js"; import { bin } from "@nand2tetris/simulator/util/twos.js"; import { Dispatch, MutableRefObject, useContext, useMemo, useRef } from "react"; import { RunSpeed } from "src/runbar.js"; @@ -198,7 +197,7 @@ export type AsmStoreDispatch = Dispatch<{ export function makeAsmStore( fs: FileSystem, - setStatus: Action, + setStatus: (status: string) => void, dispatch: MutableRefObject, upgraded: boolean, ) { diff --git a/components/src/stores/base.context.ts b/components/src/stores/base.context.ts index cf2da770..53eaaac0 100644 --- a/components/src/stores/base.context.ts +++ b/components/src/stores/base.context.ts @@ -18,7 +18,6 @@ import { createAndStoreLocalAdapterInIndexedDB, removeLocalAdapterFromIndexedDB, } from "./base/indexDb.js"; -import { Action } from "@nand2tetris/simulator/types.js"; export interface BaseContext { fs: FileSystem; @@ -27,7 +26,7 @@ export interface BaseContext { upgradeFs: (force?: boolean) => Promise; closeFs: () => void; status: string; - setStatus: Action; + setStatus: (status: string) => void; storage: Record; } diff --git a/components/src/stores/chip.store.ts b/components/src/stores/chip.store.ts index 975c4aa0..1e99105e 100644 --- a/components/src/stores/chip.store.ts +++ b/components/src/stores/chip.store.ts @@ -126,7 +126,7 @@ export type ChipStoreDispatch = Dispatch<{ export function makeChipStore( fs: FileSystem, - setStatus: Action, + setStatus: (status: string) => void, storage: Record, dispatch: MutableRefObject, upgraded: boolean, diff --git a/components/src/stores/compiler.store.ts b/components/src/stores/compiler.store.ts index e1f8a7e5..1a77ab14 100644 --- a/components/src/stores/compiler.store.ts +++ b/components/src/stores/compiler.store.ts @@ -1,7 +1,6 @@ import { FileSystem } from "@davidsouther/jiffies/lib/esm/fs.js"; import { compile } from "@nand2tetris/simulator/jack/compiler.js"; import { CompilationError } from "@nand2tetris/simulator/languages/base.js"; -import { Action } from "@nand2tetris/simulator/types.js"; import { Dispatch, MutableRefObject, useContext, useMemo, useRef } from "react"; import { useImmerReducer } from "../react.js"; import { BaseContext } from "./base.context.js"; @@ -32,7 +31,7 @@ function classTemplate(name: string) { } export function makeCompilerStore( - setStatus: Action, + setStatus: (status: string) => void, dispatch: MutableRefObject, ) { let fs: FileSystem | undefined; diff --git a/components/src/stores/cpu.store.ts b/components/src/stores/cpu.store.ts index 8ffd5cfc..f3c12f38 100644 --- a/components/src/stores/cpu.store.ts +++ b/components/src/stores/cpu.store.ts @@ -16,7 +16,6 @@ import { Span } from "@nand2tetris/simulator/languages/base.js"; import { TST } from "@nand2tetris/simulator/languages/tst.js"; import { loadAsm, loadBlob, loadHack } from "@nand2tetris/simulator/loader.js"; import { CPUTest } from "@nand2tetris/simulator/test/cputst.js"; -import { Action } from "@nand2tetris/simulator/types.js"; import { Dispatch, MutableRefObject, useContext, useMemo, useRef } from "react"; import { ScreenScales } from "src/chips/screen.js"; import { RunSpeed } from "src/runbar.js"; @@ -95,7 +94,7 @@ export type CpuStoreDispatch = Dispatch<{ export function makeCpuStore( fs: FileSystem, - setStatus: Action, + setStatus: (status: string) => void, storage: Record, dispatch: MutableRefObject, ) { diff --git a/components/src/stores/vm.store.ts b/components/src/stores/vm.store.ts index fad5f596..550b7bab 100644 --- a/components/src/stores/vm.store.ts +++ b/components/src/stores/vm.store.ts @@ -20,7 +20,6 @@ import { import { TST } from "@nand2tetris/simulator/languages/tst.js"; import { VM, VmInstruction } from "@nand2tetris/simulator/languages/vm.js"; import { VMTest, VmFile } from "@nand2tetris/simulator/test/vmtst.js"; -import { Action } from "@nand2tetris/simulator/types.js"; import { Vm, VmFrame } from "@nand2tetris/simulator/vm/vm.js"; import { Dispatch, MutableRefObject, useContext, useMemo, useRef } from "react"; import { ScreenScales } from "../chips/screen.js"; @@ -90,7 +89,7 @@ export type VmStoreDispatch = Dispatch<{ function reduceVMTest( vmTest: VMTest, dispatch: MutableRefObject, - setStatus: Action, + setStatus: (status: string) => void, showHighlight: boolean, ): VmSim { const RAM = new ImmMemory(vmTest.vm.RAM, dispatch); @@ -123,7 +122,7 @@ function reduceVMTest( export function makeVmStore( fs: FileSystem, - setStatus: Action, + setStatus: (status: string) => void, storage: Record, dispatch: MutableRefObject, ) { diff --git a/simulator/src/test/tst.ts b/simulator/src/test/tst.ts index be614f61..00f565a7 100644 --- a/simulator/src/test/tst.ts +++ b/simulator/src/test/tst.ts @@ -16,14 +16,14 @@ export abstract class Test { protected _outputList: Output[] = []; protected _log = ""; fs: FileSystem = new FileSystem(); - protected doEcho?: Action; + protected doEcho?: (status: string) => void; protected doCompareTo?: Action; protected dir?: string; protected outputFileName?: string; constructor( path?: string, - doEcho?: Action, + doEcho?: (status: string) => void, doCompareTo?: Action, ) { this.doEcho = doEcho; diff --git a/web/src/pico/inline_edit.tsx b/web/src/pico/inline_edit.tsx index eb1fee8e..9dcbbfda 100644 --- a/web/src/pico/inline_edit.tsx +++ b/web/src/pico/inline_edit.tsx @@ -1,6 +1,5 @@ import { width } from "@davidsouther/jiffies/lib/esm/dom/css/sizing"; import { useStateInitializer } from "@nand2tetris/components/react.js"; -import { Action } from "@nand2tetris/simulator/types"; import { useCallback, useState } from "react"; const Mode = { VIEW: 0, EDIT: 1 }; @@ -8,7 +7,7 @@ const Mode = { VIEW: 0, EDIT: 1 }; export const InlineEdit = (props: { mode?: keyof typeof Mode; value: string; - onChange: Action; + onChange: (value: string) => void; }) => { const [mode, setMode] = useState(props.mode ?? Mode.VIEW); const [value, setValue] = useStateInitializer(props.value); diff --git a/web/src/shell/Monaco.tsx b/web/src/shell/Monaco.tsx index 6ef0d199..bbacb943 100644 --- a/web/src/shell/Monaco.tsx +++ b/web/src/shell/Monaco.tsx @@ -4,7 +4,6 @@ import * as monacoT from "monaco-editor/esm/vs/editor/editor.api"; import { useCallback, useContext, useEffect, useRef, useState } from "react"; import { AppContext } from "../App.context"; import { Decoration, HighlightType } from "./editor"; -import { Action } from "@nand2tetris/simulator/types"; const isRangeVisible = ( editor: monacoT.editor.IStandaloneCodeEditor | undefined, @@ -80,7 +79,7 @@ export const Monaco = ({ lineNumberTransform, }: { value: string; - onChange: Action; + onChange: (value: string) => void; onCursorPositionChange?: (index: number) => void; language: string; error?: CompilationError; diff --git a/web/src/shell/editor.tsx b/web/src/shell/editor.tsx index 63ef60ee..b179c68d 100644 --- a/web/src/shell/editor.tsx +++ b/web/src/shell/editor.tsx @@ -8,7 +8,6 @@ import { Span, } from "@nand2tetris/simulator/languages/base.js"; -import { Action } from "@nand2tetris/simulator/types"; import "./editor.scss"; const Monaco = lazy(() => import("./Monaco")); @@ -35,7 +34,7 @@ const Textarea = ({ disabled = false, }: { value: string; - onChange: Action; + onChange: (value: string) => void; language: string; disabled?: boolean; }) => { @@ -83,7 +82,7 @@ export const Editor = ({ disabled?: boolean; value: string; error?: CompilationError; - onChange: Action; + onChange: (source: string) => void; onCursorPositionChange?: (index: number) => void; grammar?: Grammar; language: string;