Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fb6c2899c1 | |||
| 63e4610833 | |||
| 5a80d653c1 | |||
| a0c0c17984 |
@@ -1,18 +1,17 @@
|
||||
import { getTracerContext } from '../context';
|
||||
import type { JsonValue } from '../types';
|
||||
|
||||
interface ArrayTracerCreateOptions<T extends JsonValue> {
|
||||
interface ArrayTracerCreateOptions<T> {
|
||||
description?: string;
|
||||
initial?: T[];
|
||||
walker?: (builder: { add: (item: T) => void }) => void;
|
||||
walker?: (builder: { add: (element: T) => void }) => void;
|
||||
}
|
||||
|
||||
type ArrayTracerMetadata = {
|
||||
// initial: JsonValue[];
|
||||
interface ArrayTracerMetadata {
|
||||
length: number;
|
||||
};
|
||||
}
|
||||
|
||||
export const createArrayTracer = <T extends JsonValue = JsonValue>(
|
||||
export const createArrayTracer = <T extends JsonValue>(
|
||||
options: ArrayTracerCreateOptions<T>,
|
||||
) => {
|
||||
const { description, initial, walker } = options;
|
||||
@@ -24,13 +23,15 @@ export const createArrayTracer = <T extends JsonValue = JsonValue>(
|
||||
|
||||
const buildInitial = () => {
|
||||
if (!!initial) {
|
||||
metadata.length = initial.length;
|
||||
return [...initial];
|
||||
}
|
||||
if (!!walker) {
|
||||
const initial: T[] = [];
|
||||
walker({
|
||||
add: (item) => {
|
||||
initial.push(item);
|
||||
add: (element) => {
|
||||
initial.push(element);
|
||||
metadata.length++;
|
||||
},
|
||||
});
|
||||
return initial;
|
||||
@@ -38,8 +39,6 @@ export const createArrayTracer = <T extends JsonValue = JsonValue>(
|
||||
return [];
|
||||
};
|
||||
|
||||
// console.log(_initial);
|
||||
|
||||
const { command } = getTracerContext();
|
||||
|
||||
const validateIndex = (index: number) => {
|
||||
|
||||
Reference in New Issue
Block a user