From 2fc0c2af986c364dda7b878dd6ff1da0da3d07b5 Mon Sep 17 00:00:00 2001 From: Curran Date: Wed, 27 Nov 2024 08:38:58 -0500 Subject: [PATCH] WIP adopt new viz types package --- src/types.ts | 33 +++++---------------------------- src/viz-types.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 28 deletions(-) create mode 100644 src/viz-types.ts diff --git a/src/types.ts b/src/types.ts index 0ab67e66..360d5373 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,37 +1,14 @@ -// FileId -// * A unique ID for a file. -// * This is a random string. -export type FileId = string; +import { VizFile, VizFileId, VizFiles } from './viz-types'; + +export type FileId = VizFileId; +export type File = VizFile; +export type Files = VizFiles; // ItemId // * A unique ID for an item in the sidebar. // * This could be either a file ID or a directory path. export type ItemId = FileId | FileTreePath; -// Files -// * A collection of files. -// * Keys are _not_ file names or array indices, -// because based on past experience, that -// leads to very difficult frontend logic around -// OT in the case that a file is renamed or deleted. -// * When the file name changes, or files are added/deleted, -// this ID stays the same, simplifying things re:OT. -export interface Files { - [fileId: FileId]: File; -} - -// File -// * A file with `name` and `text`. -export interface File { - // The file name. - // e.g. "index.html". - name: string; - - // The text content of the file. - // e.g. "Hello" - text: string; -} - // FileTreePath // * The path to the directory, e.g. "src/components", OR // * The path to the file e.g. "src/components/HelloWorld.js". diff --git a/src/viz-types.ts b/src/viz-types.ts new file mode 100644 index 00000000..09560f2b --- /dev/null +++ b/src/viz-types.ts @@ -0,0 +1,28 @@ +// VizFileId +// * A unique ID for a file. +// * This is a random string. +export type VizFileId = string; + +// VizFiles +// * A collection of files. +// * Keys are _not_ file names or array indices, +// because based on past experience, that +// leads to very difficult frontend logic around +// OT in the case that a file is renamed or deleted. +// * When the file name changes, or files are added/deleted, +// this ID stays the same, simplifying things re:OT. +export type VizFiles = { + [fileId: VizFileId]: VizFile; +}; + +// VizFile +// * A file with `name` and `text`. +export type VizFile = { + // The file name. + // e.g. "index.html". + name: string; + + // The text content of the file. + // e.g. "Hello" + text: string; +};