flume

repository·master·Indexed 23 days ago

https://github.com/chrisjpatty/flume

A node-based editor library for React (version 1.2.0) that enables developers to define custom nodes, ports, and controls for building workflow editors or visual programming interfaces.

Tokens
29.7K
Snippets
89
Records
154
Agent score
79%

What's inside flume

  1. Determine if Flume is right for your application

    master

    Flume is designed for applications with complex or diverse business logic needs. It is a good fit if you encounter any of the following scenarios:

    • Your app serves users with very different business logic requirements.
    • You frequently use "feature flags" to toggle code parts for different users.
    • Business logic is frequently mixed with application logic.
    • Complicated business logic makes code hard to maintain.
    • You want to provide a visual editor so users can safely edit logic.
    • You are frequently deploying new code versions just to update business logic.
    • Non-programmers in your organization need to contribute to building application logic.
    • You struggle to share and maintain business logic between frontend and backend.
  2. What is a root-style graph and the RootEngine?

    master

    A root-style graph is a specific pattern where one node acts as the central "root" node, and all other nodes stem from it. While these graphs may look like trees, the "leaves" of the tree can be interconnected as long as they eventually feed back into the root node.

    Flume provides a RootEngine specifically optimized for efficiently resolving graphs built in this root-style architecture.

  3. What is a graph in Flume?

    master

    In Flume, a graph is a data structure used to model complex relationships between pieces of data. It is represented as a JSON object.

    Key components of a graph include:

    • Nodes: Individual pieces of data or logical units.
    • Connections: The relationships between nodes (referred to as "edges" in general graph theory).

    Flume is designed to represent logical statements (like if/then, for each, or switch) as a graph, allowing you to transform inputs into outputs through a visual, editable structure rather than hard-coded logic.

  4. Configure nodes and ports using nodeTypes and portTypes

    master

    The behavior of the Flume node editor is determined by two primary configuration objects: nodeTypes and portTypes.

    • nodeTypes: Defines the different types of nodes available in your editor.
    • portTypes: Defines the different types of ports available on those nodes.

    You can define these configurations manually as a standard JSON object, or use the FlumeConfig generator provided by Flume to simplify the creation process.

  5. Understand Flume's approach to type safety

    master
    Flume provides a form of visual type safety. It is designed to make it difficult or impossible for users to create logic that results in type errors, similar to how TypeScript works for code. While Flume is highly compatible with TypeScript, using TypeScript is not a requirement for using Flume.
  6. Understand the project folder structure

    master

    The project follows a specific structure required for the build process. The following files must exist with these exact names:

    • public/index.html: The page template.
    • src/index.js: The JavaScript entry point.

    Key Rules:

    • Processing: Only files inside src are processed by Webpack. To ensure your JS and CSS files are bundled, place them inside src.
    • Assets: Only files inside public can be used directly from public/index.html.
    • Top-level directories: You can create other top-level directories, but they will not be included in the production build (useful for documentation).
    my-app/
      README.md
      node_modules/
      package.json
      public/
        index.html
        favicon.ico
      src/
        App.css
        App.js
        App.test.js
        index.css
        index.js
        logo.svg
  7. Understand the concept of root-style graphs in Flume

    master
    Flume is designed to model "root-style" graphs. In this model, there is a single root node from which all other nodes stem. While this structure resembles a tree (parent-child relationships), it is technically a graph because "leaf" nodes can be interconnected, allowing for sibling-sibling relationships. The root node typically represents the final desired output of the logic graph.
  8. Understand Ports and type safety

    master

    A Port is the connection point on a node (represented as colored dots) that determines how nodes interact. Ports define the data types that can be passed between nodes.

    • Connection Rules: You can only create connections between ports that share the same type.
    • Customization: While examples often use colors to represent types (e.g., green for strings, blue for booleans, red for numbers), you can configure ports to output any data type and assign any color in your own implementation.
  9. Decorator support in Create React App

    master
    Currently, Create React App does not support decorator syntax because it is an experimental proposal and the current specification version is not officially supported by Babel. You should rewrite decorator-based code using standard JavaScript patterns until the specification reaches a stable stage.
  10. How logic graphs are resolved using the root engine

    master

    Flume allows you to execute modeled logic at runtime in any JavaScript environment using the root engine. The resolution process follows these steps:

    1. Entry: The engine enters the graph at the designated root node.
    2. Backward Walk: The engine loops through each input port of the root node and walks backwards through the connections to find the source of the data.
    3. Leaf Identification: The walk continues until it reaches a node that has no connected inputs (or only has literal values).
    4. Execution (Forward Pipe): Once the leaf nodes are reached, the engine begins firing the node functions. It executes the functions for the leaf nodes first, then pipes those outputs back up to the parent nodes.
    5. Completion: This continues up the chain until all required inputs for the root node's ports have been collected and processed.

    Upon completion, the root engine returns an object containing all the collected values from the root node's ports.

    Performance Note: The resolution process is highly optimized and very fast even for complex graphs. Performance bottlenecks are typically caused by the custom node functions provided by the user rather than the engine's traversal logic.

  11. Define Node Types for custom logic

    master
    To allow users to define custom logic without crashing the system, you must describe your nodes using "Node types". Each node in your graph is defined as a single type which dictates its internal behavior and its interaction patterns with other nodes. While Flume supports TypeScript, using TypeScript is not a requirement for using Flume.
  12. Pass context data into the Flume engine via `useRootEngine`

    master

    The useRootEngine hook accepts an optional third parameter: a context object. This object is the primary mechanism for passing dynamic application data into your logic graph.

    When your React component re-renders (for example, due to a state change like a user logging in), useRootEngine will run with the updated context, allowing the nodes in your graph to react to the new data and return updated attributes to your component.