import { tweakArray } from "../tweaker/tweakArray" import { isArray } from "../utils" import { withErrorPathSegment } from "../utils/errorDiagnostics" import { type FromSnapshotContext, internalFromSnapshot, registerSnapshotter } from "./fromSnapshot" import type { SnapshotInOfObject } from "./SnapshotOf" import { SnapshotterAndReconcilerPriority } from "./SnapshotterAndReconcilerPriority" function fromArraySnapshot(sn: SnapshotInOfObject, ctx: FromSnapshotContext): any[] { const ln = sn.length const arr: any[] = new Array(ln) for (let i = 0; i < ln; i++) { arr[i] = withErrorPathSegment(i, () => internalFromSnapshot(sn[i], ctx)) } return tweakArray(arr, undefined, true) } /** * @internal */ export function registerFromArraySnapshotter() { registerSnapshotter(SnapshotterAndReconcilerPriority.Array, (sn, ctx) => { if (isArray(sn)) { return fromArraySnapshot(sn, ctx) } return undefined }) }