设计tracer
This commit is contained in:
102
src/tracers.ts/index.ts
Normal file
102
src/tracers.ts/index.ts
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
const TracerType = {
|
||||||
|
ArrayTracer: 'ArrayTracer',
|
||||||
|
StackTracer: 'StackTracer',
|
||||||
|
QueueTracer: 'QueueTracer',
|
||||||
|
MatrixTracer: 'MatrixTracer',
|
||||||
|
SortTracer: 'SortTracer',
|
||||||
|
LinkTracer: 'LinkTracer',
|
||||||
|
TreeTracer: 'TreeTracer',
|
||||||
|
GraphTracer: 'GraphTracer',
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
type TracerTypeKey = keyof typeof TracerType;
|
||||||
|
|
||||||
|
type TracerTypeVal = (typeof TracerType)[TracerTypeKey];
|
||||||
|
|
||||||
|
const Action = {
|
||||||
|
Define: 'define',
|
||||||
|
|
||||||
|
Preset: 'preset',
|
||||||
|
Expand: 'expand',
|
||||||
|
Reduce: 'reduce',
|
||||||
|
Pick: 'pick',
|
||||||
|
Drop: 'drop',
|
||||||
|
Patch: 'patch',
|
||||||
|
Reset: 'reset',
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
type ActionKey = keyof typeof Action;
|
||||||
|
|
||||||
|
type ActionVal = (typeof Action)[ActionKey];
|
||||||
|
|
||||||
|
class TracerRegistry {
|
||||||
|
private tracers: Record<TracerTypeVal, string[]>;
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
this.tracers = {
|
||||||
|
ArrayTracer: [],
|
||||||
|
StackTracer: [],
|
||||||
|
QueueTracer: [],
|
||||||
|
MatrixTracer: [],
|
||||||
|
SortTracer: [],
|
||||||
|
LinkTracer: [],
|
||||||
|
TreeTracer: [],
|
||||||
|
GraphTracer: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public register(tracerType: TracerTypeVal, tracerId: string) {
|
||||||
|
this.tracers[tracerType].push(tracerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Command {
|
||||||
|
tracer: string;
|
||||||
|
action: ActionVal;
|
||||||
|
params: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Commander {
|
||||||
|
private commands: Command[];
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
this.commands = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static command() {}
|
||||||
|
|
||||||
|
public static serialize() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ArrayTracerOption<T> {
|
||||||
|
description: string;
|
||||||
|
serializeFn?: (value: T) => string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ArrayTracer<T> {
|
||||||
|
private tracerId: string;
|
||||||
|
private serializeFn?: (value: T) => string;
|
||||||
|
|
||||||
|
private constructor(option: ArrayTracerOption<T>) {
|
||||||
|
this.tracerId = crypto.randomUUID();
|
||||||
|
this.serializeFn = option.serializeFn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static define<T>(option: ArrayTracerOption<T>): ArrayTracer<T> {
|
||||||
|
return new ArrayTracer(option);
|
||||||
|
}
|
||||||
|
|
||||||
|
public preset(array: T[]) {}
|
||||||
|
|
||||||
|
public expand(size: number) {}
|
||||||
|
|
||||||
|
public reduce(size: number) {}
|
||||||
|
|
||||||
|
public pick(index: number) {}
|
||||||
|
|
||||||
|
public drop(index: number) {}
|
||||||
|
|
||||||
|
public patch(index: number, value: T) {}
|
||||||
|
|
||||||
|
public reset(index: number) {}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user