Skip to content
PACKAGES

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 { depLatest } from "@graphrefly/ts/core";
function depLatest(
ctx: Ctx,
depIndex: number,
): unknown
ParameterTypeDescription
ctxCtxNode execution context supplied by the dispatcher.
depIndexnumberZero-based dependency position in the node’s dependency list.

The latest DATA value for that dependency, or undefined when no DATA is available yet.

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]]);
});

packages/ts/src/ctx/types.ts