Compare commits
4 Commits
9aad52347b
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| fb6c2899c1 | |||
| 63e4610833 | |||
| 5a80d653c1 | |||
| a0c0c17984 |
@@ -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) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user