Skip to content

Commit

Permalink
Move Action<T> change to another PR
Browse files Browse the repository at this point in the history
  • Loading branch information
netalondon committed Jul 31, 2024
1 parent 70ab4e7 commit 7220a12
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 23 deletions.
3 changes: 1 addition & 2 deletions components/src/inline_edit.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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 };

export const InlineEdit = (props: {
mode?: keyof typeof Mode;
value: string;
highlight: boolean;
onChange: Action<string>;
onChange: (value: string) => void;
onFocus?: () => void;
}) => {
const [mode, setMode] = useState(props.mode ?? Mode.VIEW);
Expand Down
3 changes: 1 addition & 2 deletions components/src/stores/asm.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -198,7 +197,7 @@ export type AsmStoreDispatch = Dispatch<{

export function makeAsmStore(
fs: FileSystem,
setStatus: Action<string>,
setStatus: (status: string) => void,
dispatch: MutableRefObject<AsmStoreDispatch>,
upgraded: boolean,
) {
Expand Down
3 changes: 1 addition & 2 deletions components/src/stores/base.context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
createAndStoreLocalAdapterInIndexedDB,
removeLocalAdapterFromIndexedDB,
} from "./base/indexDb.js";
import { Action } from "@nand2tetris/simulator/types.js";

export interface BaseContext {
fs: FileSystem;
Expand All @@ -27,7 +26,7 @@ export interface BaseContext {
upgradeFs: (force?: boolean) => Promise<void>;
closeFs: () => void;
status: string;
setStatus: Action<string>;
setStatus: (status: string) => void;
storage: Record<string, string>;
}

Expand Down
2 changes: 1 addition & 1 deletion components/src/stores/chip.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export type ChipStoreDispatch = Dispatch<{

export function makeChipStore(
fs: FileSystem,
setStatus: Action<string>,
setStatus: (status: string) => void,
storage: Record<string, string>,
dispatch: MutableRefObject<ChipStoreDispatch>,
upgraded: boolean,
Expand Down
3 changes: 1 addition & 2 deletions components/src/stores/compiler.store.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -32,7 +31,7 @@ function classTemplate(name: string) {
}

export function makeCompilerStore(
setStatus: Action<string>,
setStatus: (status: string) => void,
dispatch: MutableRefObject<CompilerStoreDispatch>,
) {
let fs: FileSystem | undefined;
Expand Down
3 changes: 1 addition & 2 deletions components/src/stores/cpu.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -95,7 +94,7 @@ export type CpuStoreDispatch = Dispatch<{

export function makeCpuStore(
fs: FileSystem,
setStatus: Action<string>,
setStatus: (status: string) => void,
storage: Record<string, string>,
dispatch: MutableRefObject<CpuStoreDispatch>,
) {
Expand Down
5 changes: 2 additions & 3 deletions components/src/stores/vm.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -90,7 +89,7 @@ export type VmStoreDispatch = Dispatch<{
function reduceVMTest(
vmTest: VMTest,
dispatch: MutableRefObject<VmStoreDispatch>,
setStatus: Action<string>,
setStatus: (status: string) => void,
showHighlight: boolean,
): VmSim {
const RAM = new ImmMemory(vmTest.vm.RAM, dispatch);
Expand Down Expand Up @@ -123,7 +122,7 @@ function reduceVMTest(

export function makeVmStore(
fs: FileSystem,
setStatus: Action<string>,
setStatus: (status: string) => void,
storage: Record<string, string>,
dispatch: MutableRefObject<VmStoreDispatch>,
) {
Expand Down
4 changes: 2 additions & 2 deletions simulator/src/test/tst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export abstract class Test<IS extends TestInstruction = TestInstruction> {
protected _outputList: Output[] = [];
protected _log = "";
fs: FileSystem = new FileSystem();
protected doEcho?: Action<string>;
protected doEcho?: (status: string) => void;
protected doCompareTo?: Action<string>;
protected dir?: string;
protected outputFileName?: string;

constructor(
path?: string,
doEcho?: Action<string>,
doEcho?: (status: string) => void,
doCompareTo?: Action<string>,
) {
this.doEcho = doEcho;
Expand Down
3 changes: 1 addition & 2 deletions web/src/pico/inline_edit.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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 };

export const InlineEdit = (props: {
mode?: keyof typeof Mode;
value: string;
onChange: Action<string>;
onChange: (value: string) => void;
}) => {
const [mode, setMode] = useState(props.mode ?? Mode.VIEW);
const [value, setValue] = useStateInitializer(props.value);
Expand Down
3 changes: 1 addition & 2 deletions web/src/shell/Monaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -80,7 +79,7 @@ export const Monaco = ({
lineNumberTransform,
}: {
value: string;
onChange: Action<string>;
onChange: (value: string) => void;
onCursorPositionChange?: (index: number) => void;
language: string;
error?: CompilationError;
Expand Down
5 changes: 2 additions & 3 deletions web/src/shell/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -35,7 +34,7 @@ const Textarea = ({
disabled = false,
}: {
value: string;
onChange: Action<string>;
onChange: (value: string) => void;
language: string;
disabled?: boolean;
}) => {
Expand Down Expand Up @@ -83,7 +82,7 @@ export const Editor = ({
disabled?: boolean;
value: string;
error?: CompilationError;
onChange: Action<string>;
onChange: (source: string) => void;
onCursorPositionChange?: (index: number) => void;
grammar?: Grammar;
language: string;
Expand Down

0 comments on commit 7220a12

Please sign in to comment.