/** * adowire client — WireClientComponent * * Manages the client-side state for a single mounted [adowire:id] component. * Each component instance holds a reference to its root DOM element and the * latest snapshot received from the server. The `commit()` method is the * primary way to communicate with the server — it sends calls and property * updates, then morphs the DOM with the returned HTML. */ import type { WireSnapshot, WireCall } from './types.js'; export declare class WireClientComponent { /** The root DOM element that carries the `adowire:id` attribute. */ el: HTMLElement; /** The component's unique ID (value of the `adowire:id` attribute). */ id: string; /** The component's class name (value of the `adowire:name` attribute). */ name: string; /** The latest snapshot, parsed from the `adowire:snapshot` attribute. */ snapshot: WireSnapshot; /** Whether a commit is currently in-flight — prevents overlapping requests. */ private _committing; /** Queue of pending commits to flush after the current one resolves. */ private _queue; constructor(el: HTMLElement); /** * Read a property from the current snapshot state. * * For nested access you can pass a dot-separated path: * `component.get('user.email')` */ get(prop: string): any; /** * Magic action shorthand — equivalent to calling `$set` on the server. * Commits a property update without any additional method calls. * * @example * component.$set('count', 5) */ $set(prop: string, value: any): Promise; /** * Re-render the component without any calls or updates. */ $refresh(): Promise; /** * Send an action call (with optional property updates) to the server, * apply the response HTML via morphdom, and update the local snapshot. * * Commits are serialised — if one is already in-flight the new one is * queued and automatically flushed when the current request resolves. * * @param calls Array of server-side method calls to invoke. * @param updates Map of property name → new value to apply before calling. */ commit(calls: WireCall[], updates: Record): Promise; /** * Execute a single round-trip: build the payload, POST it, apply effects. * * When `calls` are present the request is sent as SSE so that any * `$stream()` calls inside the server action are pushed to the browser * in real-time (word-by-word). Non-action commits (pure property * updates / `$refresh`) use the faster plain-JSON path. */ private _doCommit; /** * Apply a single real-time stream chunk pushed over SSE. * Finds the matching `[adowire:stream="name"]` element and appends * (or replaces) its content immediately. */ private _applyStreamChunk; /** * Apply a `WireComponentResponse` from the server: * 1. Update the local snapshot so future commits carry fresh state. * 2. Morph the DOM if new HTML was returned. * 3. Process any side-effects (redirect, dispatches, title, etc.). */ private _applyResponse; /** * Flush queued commits one by one. * Batches that arrived while we were draining are merged before sending. */ private _drainQueue; }