重构tracer设计

This commit is contained in:
2026-02-04 01:07:15 +08:00
parent 0ba82716dc
commit 8d5af5876f
21 changed files with 408 additions and 225 deletions

View File

@@ -0,0 +1,102 @@
import { getTracerContext } from '../context';
import type { JsonValue } from '../types';
interface ArrayTracerCreateOptions<T extends JsonValue> {
description?: string;
array?: T[];
}
export const createArrayTracer = <T extends JsonValue>(
options: ArrayTracerCreateOptions<T>,
) => {
const { description = 'ArrayTracer', array } = options;
const tracer = crypto.randomUUID();
const { command } = getTracerContext();
command({
type: 'ArrayTracer',
tracer: tracer,
action: 'create',
params: {
description: description,
array: array,
},
});
const preset = (array: T[]) => {
command({
type: 'ArrayTracer',
tracer: tracer,
action: 'preset',
params: {
array: array,
},
});
};
const scale = (size: number) => {
command({
type: 'ArrayTracer',
tracer: tracer,
action: 'scale',
params: {
size: size,
},
});
};
const pick = (index: number) => {
command({
type: 'ArrayTracer',
tracer: tracer,
action: 'pick',
params: {
index: index,
},
});
};
const drop = (index: number) => {
command({
type: 'ArrayTracer',
tracer: tracer,
action: 'drop',
params: {
index: index,
},
});
};
const patch = (index: number, value: T) => {
command({
type: 'ArrayTracer',
tracer: tracer,
action: 'patch',
params: {
index: index,
value: value,
},
});
};
const unset = (index: number) => {
command({
type: 'ArrayTracer',
tracer: tracer,
action: 'unset',
params: {
index: index,
},
});
};
return {
// preset,
scale,
pick,
drop,
patch,
unset,
};
};