Compare commits
2 Commits
e502cb7840
...
8f5493eaf0
| Author | SHA1 | Date | |
|---|---|---|---|
| 8f5493eaf0 | |||
| 9c99af4781 |
@@ -1,10 +1,10 @@
|
|||||||
import type { TracerCommand } from "../types/command";
|
import type { TracerCommand } from "../types/command";
|
||||||
|
|
||||||
export class Commander {
|
export class Commander {
|
||||||
private commands: TracerCommand[];
|
private commands: TracerCommand<unknown>[];
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
this.commands = [];
|
this.commands = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static instance: Commander | null = null;
|
private static instance: Commander | null = null;
|
||||||
@@ -16,7 +16,7 @@ export class Commander {
|
|||||||
return this.instance;
|
return this.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public command(command: TracerCommand) {
|
public command<T = never>(command: TracerCommand<T>) {
|
||||||
this.commands.push(command);
|
this.commands.push(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ export class ArrayTracer<T> {
|
|||||||
registry.register("ArrayTracer", arrayTracer.tracerId);
|
registry.register("ArrayTracer", arrayTracer.tracerId);
|
||||||
const commander = Commander.getInstance();
|
const commander = Commander.getInstance();
|
||||||
commander.command({
|
commander.command({
|
||||||
tracer: null,
|
|
||||||
action: "define",
|
action: "define",
|
||||||
|
tracer: null,
|
||||||
params: {
|
params: {
|
||||||
type: "ArrayTracer",
|
type: "ArrayTracer",
|
||||||
id: arrayTracer.tracerId,
|
id: arrayTracer.tracerId,
|
||||||
@@ -35,21 +35,63 @@ export class ArrayTracer<T> {
|
|||||||
public preset(array: T[]) {
|
public preset(array: T[]) {
|
||||||
const commander = Commander.getInstance();
|
const commander = Commander.getInstance();
|
||||||
commander.command({
|
commander.command({
|
||||||
tracer: this.tracerId,
|
|
||||||
action: "preset",
|
action: "preset",
|
||||||
|
tracer: this.tracerId,
|
||||||
params: array,
|
params: array,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public expand(size: number) {}
|
public extend(size: number) {
|
||||||
|
const commander = Commander.getInstance();
|
||||||
|
commander.command({
|
||||||
|
action: "extend",
|
||||||
|
tracer: this.tracerId,
|
||||||
|
params: { size },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public reduce(size: number) {}
|
public shrink(size: number) {
|
||||||
|
const commander = Commander.getInstance();
|
||||||
|
commander.command({
|
||||||
|
action: "shrink",
|
||||||
|
tracer: this.tracerId,
|
||||||
|
params: { size },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public pick(index: number) {}
|
public pick(index: number) {
|
||||||
|
const commander = Commander.getInstance();
|
||||||
|
commander.command({
|
||||||
|
action: "pick",
|
||||||
|
tracer: this.tracerId,
|
||||||
|
params: { index },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public drop(index: number) {}
|
public drop(index: number) {
|
||||||
|
const commander = Commander.getInstance();
|
||||||
|
commander.command({
|
||||||
|
action: "drop",
|
||||||
|
tracer: this.tracerId,
|
||||||
|
params: { index },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public patch(index: number, value: T) {}
|
public patch(index: number, value: T) {
|
||||||
|
const commander = Commander.getInstance();
|
||||||
|
commander.command({
|
||||||
|
action: "patch",
|
||||||
|
tracer: this.tracerId,
|
||||||
|
params: { index, value },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public reset(index: number) {}
|
public reset(index: number) {
|
||||||
|
const commander = Commander.getInstance();
|
||||||
|
commander.command({
|
||||||
|
action: "reset",
|
||||||
|
tracer: this.tracerId,
|
||||||
|
params: { index },
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export * from "./array-tracer";
|
export * from "./array-tracer";
|
||||||
|
|||||||
@@ -1,52 +1,52 @@
|
|||||||
export type ArrayTracerDefineCommand = {
|
export type ArrayTracerDefineCommand = {
|
||||||
tracer: null;
|
|
||||||
action: "define";
|
action: "define";
|
||||||
|
tracer: null;
|
||||||
params: { type: "ArrayTracer"; id: string; desc?: string };
|
params: { type: "ArrayTracer"; id: string; desc?: string };
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ArrayTracerPresetCommand<T = unknown> = {
|
export type ArrayTracerPresetCommand<T = unknown> = {
|
||||||
tracer: string;
|
|
||||||
action: "preset";
|
action: "preset";
|
||||||
|
tracer: string;
|
||||||
params: T[];
|
params: T[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ArrayTracerExtendCommand = {
|
export type ArrayTracerExtendCommand = {
|
||||||
tracer: string;
|
|
||||||
action: "extend";
|
action: "extend";
|
||||||
|
tracer: string;
|
||||||
params: { size: number };
|
params: { size: number };
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ArrayTracerShrinkCommand = {
|
export type ArrayTracerShrinkCommand = {
|
||||||
tracer: string;
|
|
||||||
action: "shrink";
|
action: "shrink";
|
||||||
|
tracer: string;
|
||||||
params: { size: number };
|
params: { size: number };
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ArrayTracerPickCommand = {
|
export type ArrayTracerPickCommand = {
|
||||||
tracer: string;
|
|
||||||
action: "pick";
|
action: "pick";
|
||||||
|
tracer: string;
|
||||||
params: { index: number };
|
params: { index: number };
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ArrayTracerDropCommand = {
|
export type ArrayTracerDropCommand = {
|
||||||
tracer: string;
|
|
||||||
action: "drop";
|
action: "drop";
|
||||||
|
tracer: string;
|
||||||
params: { index: number };
|
params: { index: number };
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ArrayTracerPatchCommand<T = unknown> = {
|
export type ArrayTracerPatchCommand<T = unknown> = {
|
||||||
tracer: string;
|
|
||||||
action: "patch";
|
action: "patch";
|
||||||
|
tracer: string;
|
||||||
params: { index: number; value: T };
|
params: { index: number; value: T };
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ArrayTracerResetCommand = {
|
export type ArrayTracerResetCommand = {
|
||||||
tracer: string;
|
|
||||||
action: "reset";
|
action: "reset";
|
||||||
params: null;
|
tracer: string;
|
||||||
|
params: { index: number };
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ArrayTracerCommand<T = unknown> =
|
export type ArrayTracerCommand<T = never> =
|
||||||
| ArrayTracerDefineCommand
|
| ArrayTracerDefineCommand
|
||||||
| ArrayTracerPresetCommand<T>
|
| ArrayTracerPresetCommand<T>
|
||||||
| ArrayTracerExtendCommand
|
| ArrayTracerExtendCommand
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ import type { ArrayTracerCommand } from "./array-tracer-command";
|
|||||||
|
|
||||||
export * from "./array-tracer-command";
|
export * from "./array-tracer-command";
|
||||||
|
|
||||||
export type TracerCommand = ArrayTracerCommand
|
export type TracerCommand<T = never> = ArrayTracerCommand<T>;
|
||||||
|
|||||||
Reference in New Issue
Block a user