• English
  • Architecture - Fluxdown

    Core processes Markdown in four stages: chunking, building, mapping, and rendering. Each has its own inputs, outputs, and state. Connected together, they keep growing text readable without depending on a particular UI framework.

    Building the processing pipeline

    Edit the text or append a chunk
    Text inputBlocksBuilt HASTMapped HASTMarkdown

    Follow the same content from left to right. Edit the source or append a chunk; highlights mark the latest changes in each column. Smoothing runs at one third of its normal speed here to make the changes easier to follow.

    Chunking

    Divide the full Markdown text into blocks that can be processed separately.

    Full text
    # Weekend
    Go **outside**.
    - A book - Headphones
    TextChunker
    Block list
    1. 1
      # Weekend
    2. 2
      Go **outside**.
    3. 3
      - A book - Headphones

    Matching colors identify the same block. Blocks follow Markdown structure rather than individual lines: lists and code fences can span several lines.

    Building

    Turn each block into a syntax tree and handle unfinished syntax at the end of a stream.

    Markdown
    Go **outside
    BlockCompiler
    Syntax tree · HAST
    • p
      • Go
      • strong
        • outside

    HAST is an HTML syntax tree. Here, a paragraph contains plain and bold text. A readable result can be built before the closing ** arrives. Unchanged blocks can reuse their existing results.

    Mapping

    Control reveal progress and apply streaming effects to the existing syntax tree.

    Received
    Gooutside,takeyourtime.
    MapperComposer
    Visible now
    Gooutside,takeyourtime.

    The whole sentence has arrived on the left; only part is visible on the right. Smoothing advances through the existing build result, without parsing Markdown again for every character. Faded cells represent content that has not appeared yet.

    Rendering

    Pass the processed tree to platform components or a custom output.

    Syntax tree · HAST
    • p
      • Go
      • strong
        • outside
    Renderer
    View
    Go outside

    Core supplies the content structure. The renderer chooses the elements, styles, and interactions. The same bold node can become a web element or a native text component.

    How state closures form layers

    A state closure is an object that can produce state changes on its own, or derive them from its inputs. State closures are usually lazy: their side effects begin when their state is accessed. We use this abstraction to build the pipeline above.

    State closures organize each stage. A closure groups related computations and owns the child state it creates. The build stage, for example, keeps separate state for each block.

    textExternal text state
    Chunking stateTextChunker
    BlockCompiler
    Block ACompiledBlockContentSource · HAST · position
    Block BCompiledBlockContentSource · HAST · position
    Reveal progressSmoothCursor
    Mapping stateMapperComposer
    Rendered outputRenderer

    Adding a block and changing text within a block are distinct updates that can be subscribed to separately. Destroying Core releases its child state and subscriptions. The caller still owns the external text state.

    Connecting a rendering library

    An adapter connects application inputs to Core, subscribes to its output, and releases resources when the view unmounts.

    ApplicationText and options
    CoreObservable output
    Renderer adapterBlock list updatesUpdates within a block
    View componentsReact / Vue / …
    UnmountRelease Core and its subscriptions

    In React, for example, props update persistent input state. Changes to the block list and to individual blocks notify the corresponding components. Re-renders retain the same Core instance; unmounting releases it. Other rendering libraries can use the same division of work.

    Organizing everything with Stative

    Stative JSX describes connections between state modules. Its build runtime turns those descriptions into state flows you can read and subscribe to. Later input changes propagate through the established connections.

    /** @jsxImportSource stative */
    import { MutableState, render } from 'stative';
    
    const TextLength = ({ text }: { text: string }) => text.length;
    
    const text = MutableState.of('Hello');
    const length = render(<TextLength text={text} />);
    
    console.log(length.value.value); // 5
    text.next('Hello, Fluxdown');
    console.log(length.value.value); // 15
    
    length.destroy();
    text.destroy();

    JSX describes the connection from text to a length calculation; render turns a pipeline description such as JSX into a state closure, allowing its reactive data to be read. Core connects chunking, building, and mapping in the same way, with richer outputs. A group of connected modules can itself become a reusable state module.

    Read Stative JSX to learn about composition, or start with the Core quick start to use Core directly.