设计tracer
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { TracerCommand } from "../types/command";
|
||||
import type { TracerCommand } from '../types/command';
|
||||
|
||||
export class Commander {
|
||||
private commands: TracerCommand<unknown>[];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Commander } from "./commander";
|
||||
import { ArrayTracer } from "./tracer";
|
||||
import { Commander } from './commander';
|
||||
import { ArrayTracer } from './tracer';
|
||||
|
||||
const arrayTracer = ArrayTracer.define<number>({ description: 'Array Tracer' });
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Commander } from "../commander";
|
||||
import { Registry } from "../registry";
|
||||
import { Commander } from '../commander';
|
||||
import { Registry } from '../registry';
|
||||
|
||||
export interface ArrayTracerOption<T> {
|
||||
description: string;
|
||||
@@ -15,13 +15,13 @@ export class ArrayTracer<T> {
|
||||
public static define<T>(option: ArrayTracerOption<T>): ArrayTracer<T> {
|
||||
const arrayTracer = new ArrayTracer();
|
||||
const registry = Registry.getInstance();
|
||||
registry.register("ArrayTracer", arrayTracer.tracerId);
|
||||
registry.register('ArrayTracer', arrayTracer.tracerId);
|
||||
const commander = Commander.getInstance();
|
||||
commander.command({
|
||||
action: "define",
|
||||
action: 'define',
|
||||
tracer: null,
|
||||
payload: {
|
||||
type: "ArrayTracer",
|
||||
type: 'ArrayTracer',
|
||||
id: arrayTracer.tracerId,
|
||||
desc: option.description,
|
||||
},
|
||||
@@ -32,7 +32,7 @@ export class ArrayTracer<T> {
|
||||
public preset(array: T[]) {
|
||||
const commander = Commander.getInstance();
|
||||
commander.command({
|
||||
action: "preset",
|
||||
action: 'preset',
|
||||
tracer: this.tracerId,
|
||||
payload: array,
|
||||
});
|
||||
@@ -41,7 +41,7 @@ export class ArrayTracer<T> {
|
||||
public extend(size: number) {
|
||||
const commander = Commander.getInstance();
|
||||
commander.command({
|
||||
action: "extend",
|
||||
action: 'extend',
|
||||
tracer: this.tracerId,
|
||||
payload: { size },
|
||||
});
|
||||
@@ -50,7 +50,7 @@ export class ArrayTracer<T> {
|
||||
public shrink(size: number) {
|
||||
const commander = Commander.getInstance();
|
||||
commander.command({
|
||||
action: "shrink",
|
||||
action: 'shrink',
|
||||
tracer: this.tracerId,
|
||||
payload: { size },
|
||||
});
|
||||
@@ -59,7 +59,7 @@ export class ArrayTracer<T> {
|
||||
public pick(index: number) {
|
||||
const commander = Commander.getInstance();
|
||||
commander.command({
|
||||
action: "pick",
|
||||
action: 'pick',
|
||||
tracer: this.tracerId,
|
||||
payload: { index },
|
||||
});
|
||||
@@ -68,7 +68,7 @@ export class ArrayTracer<T> {
|
||||
public drop(index: number) {
|
||||
const commander = Commander.getInstance();
|
||||
commander.command({
|
||||
action: "drop",
|
||||
action: 'drop',
|
||||
tracer: this.tracerId,
|
||||
payload: { index },
|
||||
});
|
||||
@@ -77,7 +77,7 @@ export class ArrayTracer<T> {
|
||||
public patch(index: number, value: T) {
|
||||
const commander = Commander.getInstance();
|
||||
commander.command({
|
||||
action: "patch",
|
||||
action: 'patch',
|
||||
tracer: this.tracerId,
|
||||
payload: { index, value },
|
||||
});
|
||||
@@ -86,7 +86,7 @@ export class ArrayTracer<T> {
|
||||
public reset(index: number) {
|
||||
const commander = Commander.getInstance();
|
||||
commander.command({
|
||||
action: "reset",
|
||||
action: 'reset',
|
||||
tracer: this.tracerId,
|
||||
payload: { index },
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ArrayTracerCommand } from "../command";
|
||||
import type { ArrayTracerCommand } from '../command';
|
||||
|
||||
export type ArrayTracerAction = ArrayTracerCommand["action"];
|
||||
export type ArrayTracerAction = ArrayTracerCommand['action'];
|
||||
|
||||
export type TracerAction = ArrayTracerAction;
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
export type ArrayTracerDefineCommand = {
|
||||
action: "define";
|
||||
action: 'define';
|
||||
tracer: null;
|
||||
payload: { type: "ArrayTracer"; id: string; desc?: string };
|
||||
payload: { type: 'ArrayTracer'; id: string; desc?: string };
|
||||
};
|
||||
|
||||
export type ArrayTracerPresetCommand<T = unknown> = {
|
||||
action: "preset";
|
||||
action: 'preset';
|
||||
tracer: string;
|
||||
payload: T[];
|
||||
};
|
||||
|
||||
export type ArrayTracerExtendCommand = {
|
||||
action: "extend";
|
||||
action: 'extend';
|
||||
tracer: string;
|
||||
payload: { size: number };
|
||||
};
|
||||
|
||||
export type ArrayTracerShrinkCommand = {
|
||||
action: "shrink";
|
||||
action: 'shrink';
|
||||
tracer: string;
|
||||
payload: { size: number };
|
||||
};
|
||||
|
||||
export type ArrayTracerPickCommand = {
|
||||
action: "pick";
|
||||
action: 'pick';
|
||||
tracer: string;
|
||||
payload: { index: number };
|
||||
};
|
||||
|
||||
export type ArrayTracerDropCommand = {
|
||||
action: "drop";
|
||||
action: 'drop';
|
||||
tracer: string;
|
||||
payload: { index: number };
|
||||
};
|
||||
|
||||
export type ArrayTracerPatchCommand<T = unknown> = {
|
||||
action: "patch";
|
||||
action: 'patch';
|
||||
tracer: string;
|
||||
payload: { index: number; value: T };
|
||||
};
|
||||
|
||||
export type ArrayTracerResetCommand = {
|
||||
action: "reset";
|
||||
action: 'reset';
|
||||
tracer: string;
|
||||
payload: { index: number };
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ArrayTracerCommand } from "./array-tracer-command";
|
||||
import type { ArrayTracerCommand } from './array-tracer-command';
|
||||
|
||||
export * from "./array-tracer-command";
|
||||
export * from './array-tracer-command';
|
||||
|
||||
export type TracerCommand<T = never> = ArrayTracerCommand<T>;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ArrayTracerDefineCommand } from "../command";
|
||||
import type { ArrayTracerDefineCommand } from '../command';
|
||||
|
||||
type ArrayTracer = ArrayTracerDefineCommand["payload"]["type"];
|
||||
type ArrayTracer = ArrayTracerDefineCommand['payload']['type'];
|
||||
|
||||
export type TracerType = ArrayTracer;
|
||||
|
||||
Reference in New Issue
Block a user