rstream-graph

Declarative, reactive dataflow graph construction using @thi.ng/rstream, @thi.ng/atom and @thi.ng/transducers primitives. docs

Stream subscription types act as graph nodes and attached transducers as graph edges, transforming data for downstream consumers / nodes. Theoretically, allows cycles and is not restricted to DAG topologies, but care must be taken to avoid CPU hogging if those cycles are causing synchronous computation loops (it the user's responsibility to avoid these and keep any cycles async).

import { Atom } from 'https://esm.run/@thi.ng/atom'; import * as rs from 'https://esm.run/@thi.ng/rstream'; import * as rsg from 'https://esm.run/@thi.ng/rstream-graph';

// (optional) state atom to source value change streams from const state = new Atom({a: 1, b: 2}); // graph declaration / definition const graph = rsg.initGraph(state, { // this node sources both of its inputs // from values in the state atom add: { fn: rsg.add, ins: { a: { path: "a" }, b: { path: "b" } }, }, // this node receives values from the `add` node // and the given iterable mul: { fn: rsg.mul, ins: { a: { stream: "/add/node" }, b: { stream: () => rs.fromIterable([10, 20, 30]) } }, } }); // (optional) subscribe to individual nodes //graph.mul.subscribe({ // next: (x) => console.log("result:", x) //}); // result: 30 // result: 60 // result: 90 // changes in subscribed atom values flow through the graph setTimeout(() => state.resetIn("a", 10), 1000); // result: 360

# Application Frame

//wiki.ralfbarkow.ch/assets/pages/snippet-template/esm.html

See "Minimal rstream dataflow graph" github demo

Dataflow graph

* @thi.ng/dot - Graphviz document abstraction & serialization to DOT format * @thi.ng/resolve-map - DAG resolution of vanilla objects & arrays with internally linked values * @thi.ng/rstream-dot - Graphviz DOT conversion of @thi.ng/rstream dataflow graph topologies