UNPKG

@muban/muban

Version:

Writing components for server-rendered HTML

35 lines (34 loc) 1.83 kB
import type { PascalCase } from 'type-fest'; import type { ComponentFactory, LazyComponent } from '../Component.types'; declare type ComponentExportName<T extends string, U extends string | undefined> = undefined extends U ? PascalCase<T> : Exclude<U, undefined>; /** * A wrapper to allow the registration of "lazy" components. * * Instead of providing an actual Component to the `components` array within * `defineComponent`, this wrapper can be used to provide a "lazy" component. * * Lazy components are only loaded when the passed `displayName` * (1st parameter) exists as a `data-component` attribute in the DOM. * * When that is the case, the `getComponent` (2nd parameter) is called, which * should return a `Promise` with the module exports. * * Once loaded, it tries to use the export that matches the `PascalCase` version * of the `displayName` (which is the default convention). If for some reason * the export doesn't match this convention, or a file exports two components, * you can provide the `exportName` (3rd parameter) to be used instead. * * @param {string} displayName The name of the component declared in the defineComponent() function * @param {function} getComponent A function that returns an import of the component file * @param {string} exportName The name of the exported component * @returns {Object} LazyComponent */ export declare function lazy<T extends string, U extends string | undefined>(displayName: T, getComponent: () => Promise<{ [Key in ComponentExportName<T, U>]: ComponentFactory; }>, exportName?: U): LazyComponent; /** * @deprecated */ export declare function supportLazy(component: ComponentFactory): ComponentFactory<any, any>; export declare function isLazyComponent(component: ComponentFactory | LazyComponent): component is LazyComponent; export {};