class / @typed/template/HtmlChunk

HtmlChunksBuilder

Advanced mutable builder used by the published template-to-chunk compiler.

Package version
1.0.0-beta.7
Category
HTML chunk assembly
Since
1.0.0
Stability
internal-but-published

Import

import { HtmlChunksBuilder } from "@typed/template/HtmlChunk";

Signatures

export declare class HtmlChunksBuilder {
    text(text: string): HtmlChunksBuilder;
    part(node: Template.PartNode, render: (value: unknown) => string): HtmlChunksBuilder;
    sparsePart(node: Template.SparsePartNode, render: (value: unknown) => string): HtmlChunksBuilder;
    build(): ReadonlyArray<HtmlChunk>;
}

Why

Adjacent static strings are coalesced during compilation so runtime streaming performs fewer writes. This is published renderer-author infrastructure, not a raw-HTML application API.

Ownership and lifetime

One builder exclusively owns its mutable buffer. build transfers the current array and resets the builder for reuse; it acquires no Scope.

Method: build

Transfers the accumulated chunks and resets the builder.

Method: build: Why

Allows one compiler-local builder to create independent chunk arrays.

Method: build: Ownership and lifetime

The caller receives the prior array; the builder starts a new empty buffer.

Method: part

Appends one dynamic part and its context-specific serializer.

Method: part: Why

Keeps escaping behavior adjacent to the parsed part.

Method: part: Ownership and lifetime

Retains the node and pure function until build transfers the buffer.

Method: sparsePart

Appends one sparse dynamic part and serializer.

Method: sparsePart: Why

Preserves literal/dynamic ordering under one escaping context.

Method: sparsePart: Ownership and lifetime

Retains the node and function until build transfers the buffer.

Method: text

Appends static text and coalesces it with the preceding text chunk.

Method: text: Why

Coalescing reduces output writes before runtime rendering begins.

Method: text: Ownership and lifetime

Mutates only this builder’s private buffer.

Examples

import { HtmlChunksBuilder } from "@typed/template/HtmlChunk"

const chunks = new HtmlChunksBuilder().text("<p>hello</p>").build()

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source