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