设计tracer

This commit is contained in:
2025-11-10 02:44:50 +08:00
parent e502cb7840
commit 9c99af4781
5 changed files with 16 additions and 16 deletions

View File

@@ -1,10 +1,10 @@
import type { TracerCommand } from "../types/command";
export class Commander {
private commands: TracerCommand[];
private commands: TracerCommand<unknown>[];
private constructor() {
this.commands = [];
this.commands = [];
}
private static instance: Commander | null = null;
@@ -16,7 +16,7 @@ export class Commander {
return this.instance;
}
public command(command: TracerCommand) {
public command<T = never>(command: TracerCommand<T>) {
this.commands.push(command);
}

View File

@@ -41,9 +41,9 @@ export class ArrayTracer<T> {
});
}
public expand(size: number) {}
public extend(size: number) {}
public reduce(size: number) {}
public shrink(size: number) {}
public pick(index: number) {}

View File

@@ -1 +1 @@
export * from "./array-tracer";
export * from "./array-tracer";

View File

@@ -1,52 +1,52 @@
export type ArrayTracerDefineCommand = {
tracer: null;
action: "define";
tracer: null;
params: { type: "ArrayTracer"; id: string; desc?: string };
};
export type ArrayTracerPresetCommand<T = unknown> = {
tracer: string;
action: "preset";
tracer: string;
params: T[];
};
export type ArrayTracerExtendCommand = {
tracer: string;
action: "extend";
tracer: string;
params: { size: number };
};
export type ArrayTracerShrinkCommand = {
tracer: string;
action: "shrink";
tracer: string;
params: { size: number };
};
export type ArrayTracerPickCommand = {
tracer: string;
action: "pick";
tracer: string;
params: { index: number };
};
export type ArrayTracerDropCommand = {
tracer: string;
action: "drop";
tracer: string;
params: { index: number };
};
export type ArrayTracerPatchCommand<T = unknown> = {
tracer: string;
action: "patch";
tracer: string;
params: { index: number; value: T };
};
export type ArrayTracerResetCommand = {
tracer: string;
action: "reset";
tracer: string;
params: null;
};
export type ArrayTracerCommand<T = unknown> =
export type ArrayTracerCommand<T = never> =
| ArrayTracerDefineCommand
| ArrayTracerPresetCommand<T>
| ArrayTracerExtendCommand

View File

@@ -2,4 +2,4 @@ import type { ArrayTracerCommand } from "./array-tracer-command";
export * from "./array-tracer-command";
export type TracerCommand = ArrayTracerCommand
export type TracerCommand<T = never> = ArrayTracerCommand<T>;