UNPKG

@ndbx/runtime

Version:

The `@ndbx/runtime` package provides a runtime environment to embed NodeBox visualizations directly into React applications. NodeBox is a powerful tool for creating interactive and generative visualizations, and this runtime allows you to integrate those

24 lines (20 loc) 616 B
/** * Run an expression on each item in an array and return the results. */ export default function (node) { const tableIn = node.tableIn({ name: "table" }); const sourceIn = node.stringIn({ name: "source", widget: "TEXT", value: "return { ...d };" }); const tableOut = node.tableOut({ name: "out" }); node.onRender = async () => { const data = tableIn.value; const fn = new Function("d", sourceIn.value); if (Array.isArray(data)) { const rows = data.map(fn); tableOut.set(rows); } else { const result = fn(data); tableOut.set(result); return; } }; }