UNPKG

@thi.ng/rdom

Version:

Lightweight, reactive, VDOM-less UI/DOM components with async lifecycle and @thi.ng/hiccup compatible

41 lines 1.65 kB
import type { Maybe, Path } from "@thi.ng/api"; import type { IComponent, IMountWithState, NumOrElement } from "./api.js"; /** * Takes an ES `AsyncIterable` and creates a simple component wrapper for its * asynchronously produced values. * * @remarks * If given an {@link IMountWithState} component, new values are applied via the * `.update()` life cycle value. If given a `tag` and `attribs`, a corresponding * element wrapper component will be created automatically (using * {@link $wrapText} and incoming values will be applied using {@link $text} * (aka setting `el.innerText`). * * @example * ```ts * import { $async } from "@thi.ng/rdom"; * import { range } from "@thi.ng/transducers-async"; * * // infinite 1Hz counter * const counter = range(1000); * * // wrapper component which updates whenever counter produces new values * $async(counter, "div", { class: "red" }).mount(document.body); * ``` * * @param src - * @param inner - */ export declare function $async<T>(src: AsyncIterable<T>, inner: IMountWithState<T>): IComponent<T>; export declare function $async(src: AsyncIterable<any>, tag: string, attribs?: any): IComponent; export declare class $Async<T = any> { protected src: AsyncIterable<T>; protected inner: IMountWithState<Maybe<T>>; el?: Element; constructor(src: AsyncIterable<T>, inner: IMountWithState<Maybe<T>>); mount(parent: ParentNode, index?: NumOrElement): Promise<Element>; unmount(): Promise<void>; update(x: T): void; } export declare const $asyncA: (src: AsyncIterable<any>, comp: IComponent, path: Path) => Promise<void>; //# sourceMappingURL=async.d.ts.map