Package Exports
- @thi.ng/rstream-graph
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@thi.ng/rstream-graph) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@thi.ng/rstream-graph
This project is part of the @thi.ng/umbrella monorepo.
About
Declarative, reactive dataflow graph construction using @thi.ng/rstream, @thi.ng/atom and @thi.ng/transducers primitives.
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 (user's responsibility).
Installation
yarn add @thi.ng/rstream-graph
Usage examples
Small(ish), fully commented projects can be found in the /examples
folder:
- Dataflow circles - Source, Live version
- SVG grid gen - Source, Live version
More basic:
import { Atom } from "@thi.ng/atom";
import * as rs from "@thi.ng/rstream";
import * as rsg from "@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" },
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
Please documentation in the source code for further details.
Authors
- Karsten Schmidt
License
© 2018 Karsten Schmidt // Apache Software License 2.0