import type { Fn } from "@thi.ng/api" ; import type { ComponentLike , IComponent , NumOrElement } from "./api.js" ; import { Component } from "./component.js" ; /**
 * Simple component wrapper for  ComponentLike promises. When this
 * component mounts it will `await` the given promise or if it fails, compile
 * the result of the given (optional) `error` handler as component body.
 *
 *  example param prom param error export const $promise = ( prom , error ? ) => new $Promise ( prom , error ) ; export class $Promise extends Component { inner ? : IComponent ; constructor ( protected promise , protected error = ( e ) => e ) { super ( ) ; } async mount ( parent , index ) { try { this . inner = this . $compile ( await this . promise ) ; } catch ( e ) { this . inner = this . $compile ( this . error ( < Error > e ) ) ; } return ( this . el = await this . inner . mount ( parent , index ) ) ; } async unmount ( ) { await this . inner ! . unmount ( ) ; this . inner = undefined ; this . el = undefined ; } }