@muban/muban
Version:
Writing components for server-rendered HTML
51 lines (50 loc) • 2.63 kB
TypeScript
import type { ComponentApi, ComponentFactory, InternalComponentInstance, LazyComponent } from '../Component.types';
import type { PropertySource } from '../props/getComponentProps';
declare class MubanGlobal {
readonly components: Map<string, ComponentFactory<any, any> | LazyComponent<any, any>>;
readonly instances: Map<HTMLElement, {
readonly name: string;
setProps: (props: import("../..").TypedProps<any>) => void;
readonly props: import("../..").TypedProps<any>;
readonly element: HTMLElement;
setup: () => void;
dispose: () => void;
__instance: InternalComponentInstance;
}>;
readonly loadingElements: Set<HTMLElement>;
readonly propertySources: Array<PropertySource>;
}
declare global {
interface Window {
__muban__: MubanGlobal;
}
}
export declare function getGlobalMubanInstance(): MubanGlobal;
export declare function registerGlobalComponent(...components: Array<ComponentFactory | LazyComponent>): void;
/**
* 1. Start initializing components:
* - either a single one calling "mount(component, container)"
* - or a single one calling "component(element)"
* - or multiple calling "initGlobalComponents(container)"
* - this will only try to initialize "direct child components" of the container
*
* 2. Each of the above components will:
* - query and instantiate its own ref components (will recurse for each with its children at point 2)
* - query and instantiate its "optional" sync components (will recurse for each with its children at point 2)
* - query and start loading its "optional" lazy components
* once loaded, this will also instantiate the component (and will also recurse for its children at point 2)
*
* 3. If there are any "direct child components" left that are 1) not initialized or 2) not lazy loading
* - try to initialize those globally (will recurse at point 2)
* - if there are elements that cannot be initialized (because there are no matching components registered)
* - recurse each "direct child component" container at point 3)
*
* @param container
* @param watch
*/
export declare function initGlobalComponents(container: HTMLElement, watch?: boolean): void;
export declare function getComponentForElement<T extends ComponentApi>(element: HTMLElement): T | undefined;
export declare function registerComponentForElement(element: HTMLElement, instance: ComponentApi): void;
export declare function getParents(component: ComponentApi): Array<ComponentApi>;
export declare function setComponentElementLoadingState(element: HTMLElement, isLoading: boolean): void;
export {};