refactor(array-tracer): 移除 preset 指令并简化类型参数
- 将 preset 功能合并到 create 指令中,简化 API 设计 - 移除 ArrayTracerPresetCommand 类型及相关处理逻辑 - 调整 createArrayTracer 泛型参数以直接接受数组类型 - 更新相关文档以反映新的初始化模式
This commit is contained in:
@@ -8,7 +8,7 @@ import {
|
||||
const logTracer = createLogTracer({ description: 'LogTracer' });
|
||||
const controlTracer = createControlTracer({ description: 'ControlTracer' });
|
||||
|
||||
const arrayTracer = createArrayTracer<number>({
|
||||
const arrayTracer = createArrayTracer({
|
||||
description: 'ArrayTracer',
|
||||
array: [1, 2, 3],
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { getTracerContext } from '../context';
|
||||
import type { JsonValue } from '../types';
|
||||
|
||||
interface ArrayTracerCreateOptions<T extends JsonValue> {
|
||||
interface ArrayTracerCreateOptions<T extends JsonValue[]> {
|
||||
description?: string;
|
||||
array?: T[];
|
||||
array?: T;
|
||||
}
|
||||
|
||||
export const createArrayTracer = <T extends JsonValue>(
|
||||
export const createArrayTracer = <T extends JsonValue[]>(
|
||||
options: ArrayTracerCreateOptions<T>,
|
||||
) => {
|
||||
const { description = 'ArrayTracer', array } = options;
|
||||
@@ -24,17 +24,6 @@ export const createArrayTracer = <T extends JsonValue>(
|
||||
},
|
||||
});
|
||||
|
||||
const preset = (array: T[]) => {
|
||||
command({
|
||||
type: 'ArrayTracer',
|
||||
tracer: tracer,
|
||||
action: 'preset',
|
||||
params: {
|
||||
array: array,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const scale = (size: number) => {
|
||||
command({
|
||||
type: 'ArrayTracer',
|
||||
@@ -68,7 +57,7 @@ export const createArrayTracer = <T extends JsonValue>(
|
||||
});
|
||||
};
|
||||
|
||||
const patch = (index: number, value: T) => {
|
||||
const patch = (index: number, value: T[number]) => {
|
||||
command({
|
||||
type: 'ArrayTracer',
|
||||
tracer: tracer,
|
||||
@@ -92,7 +81,6 @@ export const createArrayTracer = <T extends JsonValue>(
|
||||
};
|
||||
|
||||
return {
|
||||
// preset,
|
||||
scale,
|
||||
pick,
|
||||
drop,
|
||||
|
||||
@@ -12,13 +12,6 @@ type ArrayTracerCreateCommand = BaseArrayTracerCommand & {
|
||||
};
|
||||
};
|
||||
|
||||
type ArrayTracerPresetCommand = BaseArrayTracerCommand & {
|
||||
action: 'preset';
|
||||
params: {
|
||||
array: JsonValue[];
|
||||
};
|
||||
};
|
||||
|
||||
type ArrayTracerScaleCommand = BaseArrayTracerCommand & {
|
||||
action: 'scale';
|
||||
params: {
|
||||
@@ -57,7 +50,6 @@ type ArrayTracerUnsetCommand = BaseArrayTracerCommand & {
|
||||
|
||||
export type ArrayTracerCommand =
|
||||
| ArrayTracerCreateCommand
|
||||
| ArrayTracerPresetCommand
|
||||
| ArrayTracerScaleCommand
|
||||
| ArrayTracerPickCommand
|
||||
| ArrayTracerDropCommand
|
||||
|
||||
Reference in New Issue
Block a user