depLatest()
Read the most recent DATA value from one upstream dependency during a node run.
depIndex is positional: 0 reads the first dependency in node([first, ...]), 1 reads the
second dependency, and so on. If that dependency has not produced DATA in the current graph
lifecycle, the value is undefined.
Import
Section titled “Import”import { depLatest } from "@graphrefly/ts/core";Signature
Section titled “Signature”function depLatest( ctx: Ctx, depIndex: number,): unknownParameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
ctx | Ctx | Node execution context supplied by the dispatcher. |
depIndex | number | Zero-based dependency position in the node’s dependency list. |
Returns
Section titled “Returns”The latest DATA value for that dependency, or undefined when no DATA is available yet.
Example
Section titled “Example”import { depLatest, node } from "@graphrefly/ts/core";
const count = node<number>([], null, { initial: 1 });const doubled = node<number>([count], (ctx) => { const latest = depLatest(ctx, 0); if (latest === undefined) return; ctx.down([["DATA", Number(latest) * 2]]);});Source
Section titled “Source”packages/ts/src/ctx/types.ts