@thi.ng/rstream-graph3.0.23 • Public • Published
This project is part of the @thi.ng/umbrella monorepo.
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).
yarn add @thi.ng/rstream-graph
Small(ish), fully commented projects can be found in the
;;;// (optional) state atom to source value change streams from;// graph declaration / definition;// (optional) subscribe to individual nodesgraph.mul.subscribe;// result: 30// result: 60// result: 90// changes in subscribed atom values flow through the graphsetTimeoutstate.resetIn"a", 10, 1000;// result: 360
A dataflow graph spec is a plain object where keys are node names and
their values are
NodeSpecs, defining a node's inputs, outputs and the
operation to be applied to produce one or more result streams.
Specification for a single "node" in the dataflow graph. Nodes here are
actually just wrappers of streams / subscriptions (or generally any form
ISubscribable), usually with an associated transducer to transform /
combine the inputs and produce values for the node's result stream.
fn function is responsible to produce such a stream transformer
construct and the library provides several general purpose helpers for
that purpose. The keys used to specify inputs in the
ins object are
dictated by the actual node
fn used. Most node functions with multiple
inputs will be implemented as
instances and the input IDs are used to locally rename input streams
StreamSync container. Alo see
for more details how these specs are compiled into stream constructs.
Specification for a single input, which can be given in different ways:
- Create a stream of value changes at given path in state
- Reference path to another node's output in the GraphSpec object. See @thi.ng/resolve-map for details.
// main node output// specific output
- Reference another node indirectly. The passed in
resolvefunction can be used to lookup other nodes, with the same logic as above. E.g. the following spec looks up the main output of node "abc" and adds a transformed subscription, which is then used as input for current node.
- Provide an external input stream:
- Single value input stream:
If the optional
xform key is given, a subscription with the given
transducer is added to the input and then used as input instead. This is
allows for further pre-processing of inputs.
Please see detailed documentation in the source code & test cases for further details.
- Karsten Schmidt
© 2018 Karsten Schmidt // Apache Software License 2.0