/** * Async generator support for templates. * * This module provides opt-in support for async generators in templates, * enabling loading states, progressive content, and automatic restart * when signal dependencies change. * * @example * ```ts * import { html as baseHtml, signal } from "balises"; * import asyncPlugin from "balises/async"; * * const html = baseHtml.with(asyncPlugin); * const userId = signal(1); * * // Async generators are auto-detected - no wrapper needed! * html`
${async function* () { * yield html`Loading user ${userId.value}...`; * const user = await fetchUser(userId.value); * return html`${user.name}`; * }}
`.render(); * ``` */ import { type InterpolationPlugin } from "./template.js"; /** * Opaque handle representing settled content from an async generator. * * When an async generator restarts due to signal changes, it receives the * previous settled content as its first argument. Return this value to * preserve the existing DOM instead of re-rendering. * * @example * ```ts * import asyncPlugin, { type RenderedContent } from "balises/async"; * * async function* loadUser( * settled?: RenderedContent, * ctx?: AsyncGeneratorContext<{ lastId?: number }>, * ) { * const id = userId.value; // Track dependency * const previous = ctx?.lastId; * ctx && (ctx.lastId = id); * * if (settled) { * // Restart: update state, keep existing DOM * const user = await fetchUser(id); * state.user = user; // Triggers surgical updates via reactive bindings * return settled; // Preserve DOM * } * * // First load * yield html`
...
`; * const user = await fetchUser(id); * state.user = user; * return UserCard({ state }); * } * ``` */ export interface RenderedContent { /** @internal Brand to prevent construction outside the library */ readonly __brand: "RenderedContent"; } /** * Mutable context object that persists across async generator restarts. */ export type AsyncGeneratorContext> = T; /** * Plugin that handles async generator functions. * Auto-detects `async function*` without needing a wrapper. */ declare const asyncPlugin: InterpolationPlugin; export default asyncPlugin; //# sourceMappingURL=async.d.ts.map