UNPKG

@knyt/luthier

Version:

A library for building standardized, type-safe native web components with full SSR and hydration support.

69 lines 2.75 kB
import { type ReactiveController, type ReactiveControllerHost } from "@knyt/tasker"; import type { KnytContent } from "@knyt/weaver"; import type { PromiseReference } from "./PromiseReference"; /** * @internal scope: module */ type DeferredContentHost = ReactiveControllerHost & HTMLElement; /** * @internal scope: module */ export declare class DeferredContentRenderer<T extends PromiseReference.Collection<any>> implements ReactiveController { #private; constructor(host: DeferredContentHost, references: T); /** * @internal scope: module */ hostConnected(): void; /** * @internal scope: module */ hostDisconnected(): void; /** * Creates a render function that defers rendering while any of the * promises of the previously given references are unresolved. * * @remarks * * Whenever any of the references change, the rendering will be deferred again * until all new promises have resolved. * * While the rendering is deferred, a `DeferredContent` component higher in the * DOM tree may display a placeholder UI while loading is in progress. * * When all promises have resolved, the provided render function is called * with the resolved values, and its result is rendered. However, if any other * elements are being deferred under the `DeferredContent` element, the * placeholder will continue to be shown until all deferred content is ready. */ thenRender(renderFn: (...data: PromiseReference.Collection.Unwrapped<T>) => KnytContent | Promise<KnytContent>): () => KnytContent | Promise<KnytContent>; /** * Cleans up resources used by the controller and removes it from the host. */ destroy(): void; } /** * Signals a parent `DeferredContent` element to delay revealing its * content until the provided promise settles. */ export declare function defer<T>(host: DeferredContentHost, promise: Promise<T>): void; /** * Signals a parent `DeferredContent` element to delay revealing its * content while any of the promises of the given references are unresolved. * * @remarks * * The returned `DeferredContentRenderer` instance can be used to create * a render function that receives the resolved values of the promises. * This allows rendering the content with the resolved data once all * promises have settled. */ export declare function defer<T extends PromiseReference.Collection<any>>(host: DeferredContentHost, ...references: T): DeferredContentRenderer<T>; export declare namespace defer { /** * @internal scope: workspace */ type Renderer<T extends PromiseReference.Collection<any>> = DeferredContentRenderer<T>; } export {}; //# sourceMappingURL=defer.d.ts.map