Compare commits

...

4 Commits

Author SHA1 Message Date
skycurtain fb6c2899c1 refactor: 将回调参数名从 item 重命名为 element
使参数名更准确地反映其表示数组元素而非通用项的含义,提升代码可读性。
2026-03-04 14:50:03 +08:00
skycurtain 63e4610833 fix(array-tracer): 修复初始数组长度元数据未更新的问题
在构建初始数组时,同步更新metadata.length,确保元数据与数组实际状态一致。
2026-03-04 14:48:22 +08:00
skycurtain 5a80d653c1 refactor(array-tracer): 移除泛型默认值并重命名参数
- 移除 `T extends JsonValue = JsonValue` 中的默认类型参数
- 将接口中的 `item` 参数重命名为 `element` 以提高可读性
- 删除被注释掉的调试代码 `console.log`
2026-03-04 14:45:57 +08:00
skycurtain a0c0c17984 refactor(tracers): 简化 ArrayTracerMetadata 为接口类型
将类型别名改为接口声明,并移除已被注释的属性,使类型定义更清晰。
2026-03-04 11:24:10 +08:00
+9 -10
View File
@@ -1,18 +1,17 @@
import { getTracerContext } from '../context'; import { getTracerContext } from '../context';
import type { JsonValue } from '../types'; import type { JsonValue } from '../types';
interface ArrayTracerCreateOptions<T extends JsonValue> { interface ArrayTracerCreateOptions<T> {
description?: string; description?: string;
initial?: T[]; initial?: T[];
walker?: (builder: { add: (item: T) => void }) => void; walker?: (builder: { add: (element: T) => void }) => void;
} }
type ArrayTracerMetadata = { interface ArrayTracerMetadata {
// initial: JsonValue[];
length: number; length: number;
}; }
export const createArrayTracer = <T extends JsonValue = JsonValue>( export const createArrayTracer = <T extends JsonValue>(
options: ArrayTracerCreateOptions<T>, options: ArrayTracerCreateOptions<T>,
) => { ) => {
const { description, initial, walker } = options; const { description, initial, walker } = options;
@@ -24,13 +23,15 @@ export const createArrayTracer = <T extends JsonValue = JsonValue>(
const buildInitial = () => { const buildInitial = () => {
if (!!initial) { if (!!initial) {
metadata.length = initial.length;
return [...initial]; return [...initial];
} }
if (!!walker) { if (!!walker) {
const initial: T[] = []; const initial: T[] = [];
walker({ walker({
add: (item) => { add: (element) => {
initial.push(item); initial.push(element);
metadata.length++;
}, },
}); });
return initial; return initial;
@@ -38,8 +39,6 @@ export const createArrayTracer = <T extends JsonValue = JsonValue>(
return []; return [];
}; };
// console.log(_initial);
const { command } = getTracerContext(); const { command } = getTracerContext();
const validateIndex = (index: number) => { const validateIndex = (index: number) => {