dflow
    TypeScript icon, indicating that this package has built-in type declarations

    0.29.0 • Public • Published

    dflow

    is a minimal Dataflow programming engine

    Features

    • Implemented in TypeScript, available both on Node and on Deno.
    • Expressive API.
    • Graphic interface implemented with WebComponents (demo here).
    • Core nodes catalog with basic JavaScript features (to be completed).
    • Supports custom nodes, just extending DflowNode class.

    Installation

    Node

    With npm do

    npm install dflow

    Deno

    Create an import_map.json file like this.

    {
      "imports": {
        "dflow/": "https://unpkg.com/dflow/"
      }
    }

    Then you can import for example the following.

    import { DflowHost } from "dflow/engine.ts";
    import { catalog as coreNodes } from "dflow/nodes/catalog.ts";
    
    const dflow = new DflowHost(coreNodes);

    With deno you can then launch your script like this

    deno run --importmap=import_map.json path/to/my/script.ts

    It is recommended to point to a specific version, for instance to point to version 0.26 or whatever, then change your import map accordingly

    {
      "imports": {
    -    "dflow/": "https://unpkg.com/dflow/"
    +    "dflow/": "https://unpkg.com/dflow@0.26/"
      }
    }

    Usage

    This is a trivial sample graph that will run sin(π / 2) = 1 computation.

      --------------
      number = π / 2
      --------------
      |
      |
      -------
      mathSin
      -------
      |
      |
     ------------
    | consoleLog |
     ------------
    

    You can run the following code with any of the following:

    • launching command deno run https://raw.githubusercontent.com/fibo/dflow/main/examples/usage.js
    • cloning this repo and launching node examples/usage.js.

    You should see a number 1 printed on output.

    // file examples/usage.js
    import { catalog as corenodes, dflowhost } from "../dflow.js";
    
    function rungraph() {
      // use builtin nodes
      const dflow = new dflowhost(corenodes);
    
      // create nodes
      const numnode = dflow.newnode({
        kind: "number",
      });
      const sinnode = dflow.newnode({
        kind: corenodes.mathsin.kind,
      });
      const consolelognode = dflow.newnode({
        kind: corenodes.consolelog.kind,
      });
    
      // set numnode output to π / 2
      numnode.output(0).data = math.pi / 2;
    
      // connect numnode to sinnode and sinnode to consolelog
      dflow.connect(numnode).to(sinnode);
      dflow.connect(sinnode).to(consolelognode);
    
      // run graph
      dflow.run();
    }
    
    rungraph();

    License

    MIT

    Install

    npm i dflow

    DownloadsWeekly Downloads

    144

    Version

    0.29.0

    License

    MIT

    Unpacked Size

    128 kB

    Total Files

    42

    Last publish

    Collaborators

    • fibo