Documentation / @finchart/core / index / reuseUnchanged
Function: reuseUnchanged()
reuseUnchanged<
TOut>(previous,next):TOut
Defined in: packages/core/src/data/computation.ts:168
Hands back the previous output object wherever the new one is the same plain record — the explicit way for a full recompute to meet calcLast's identity requirement:
calcLast: (previous, inputs) => reuseUnchanged(previous, calc(...inputs)),Downstream, a change's shape is read from point identity (tailDelta): with every position a fresh object, a one-bar tick reads as a full change and every consumer re-validates and copies its whole array.
Why a call, not something the node does on its own: the points are compared as plain data records — plain objects whose own enumerable string keys are their whole state, with === values (NaN never matches; 0 and -0 are told apart). That is a fact about the { x, y } literal your calc built; it is not something a node can assume about arbitrary output — a value behind a getter, a symbol key, a cache keyed by the object itself would all be missed — so a node without calcLast keeps every new object. Anything not a plain object (a class instance, a Proxy, a non-object entry) is not judged and stays the new object.
Pure: neither argument is touched. A branch with nothing to reuse is returned as is; otherwise a copy carries the reused objects (frozen in, frozen out). The walk costs about 5× the map that produced the points — measured ~70 ns per point: 14 ms for 100k × 2 branches, 1.4 ms for 10k × 2 — against the full path it prevents, which re-validates and re-maps every point per consumer.
Type Parameters
TOut
TOut extends Record<string, BaseDataPoint[]>
Parameters
previous
TOut
next
TOut
Returns
TOut