UNPKG

@kloudsoftware/eisen

Version:

Declarative and expressive TypeScript framework for building modern web applications

135 lines (134 loc) 5.26 kB
import { Attribute, VInputNode, VNode, VNodeType } from './VNode'; import { Renderer } from './render'; import { Props } from './Props'; import { Component, ComponentHolder } from './Component'; import { EventHandler } from './EventHandler'; import { IRouter } from '../Router'; import { Resolver } from '../i18n/Resolver'; import { EventPipeline } from './GlobalEvent'; export declare const unmanagedNode: string; export declare type AppEvent = () => void; export declare type ComponentEvent = (comp: Component) => void; export declare type FunctionHolder = [boolean, AppEvent]; export declare type ComponentFunctionHolder = [boolean, ComponentEvent]; export interface NodeOptions { attrs?: Attribute[]; props?: Props; value?: string; } export declare class VApp { rootNode: VNode; targetId: string; dirty: boolean; snapshots: VApp[]; renderer: Renderer; eventListeners: AppEvent[]; initial: boolean; compProps: Array<ComponentHolder>; compsToNotifyUnmount: Array<AppEvent>; eventHandler: EventHandler; router?: IRouter; pluginMap: Map<string, any>; oneTimeRenderCallbacks: AppEvent[]; i18nResolver?: Array<Resolver>; eventPipeLine: EventPipeline; /** * Constructs the app * @param targetId id of the DOM mountpoint, defined in your index.html * @param renderer an Instance of the Renderer * @param rootNode Used to clone the VApp, ignore on creation of a new one */ constructor(targetId: string, renderer: Renderer, rootNode?: VNode); /** * Use the default router for this app * @param mount The mountpoint for the Router */ useRouter(mount: VNode): IRouter; /** * Use custom router for this app * @param router The custom router instance */ useCustomRouter(router: IRouter): IRouter; /** * Adds a callback to the initial render of this app, its executed after the initial render is done and all elements of it are on the dom. * @param listener */ addInitialRenderEventlistener(listener: AppEvent): void; /** * Mounts a component to this app * @param component The component to mount * @param mount the mountpoint for the Component * @param props Any properties, passed into the Component */ mountComponent(component: Component, mount: VNode, props: Props): VNode; mountSubComponent(component: Component, mount: VNode, props: Props, parent: Component): void; rerenderComponent(component: Component, props: Props): void; notifyUnmount(node: VNode): void; /** * Mounts a component and returns the full ComponentHolder, used by the Router * @param component * @param mount * @param props */ routerMountComponent(component: Component, mount: VNode, props: Props): ComponentHolder; /** * Remounts a previously mounted component. Primarily used by the Router * @param holder The ComponentHolder object, holds necessary callbacks * @param mount Mountpoint for this component */ remountComponent(holder: ComponentHolder, mount: VNode): void; /** * Unmounts a component that was mounted on this app * @param mount Mountpoint, returned by VApp.mountComponent */ unmountComponent(mount: VNode): void; getComponentsWithMountAs(mount: VNode): Array<Component>; init(): void; /** Notifies that a redraw of the app is needed */ notifyDirty(): void; getLatestSnapshot(): VApp | undefined; getPreviousSnapshot(): VApp | undefined; clone(): VApp; /** * Creates a VNode and appends it as a child to the parentNode * @param tagName HTML tagName * @param content Value of the element(innerHTML) * @param parentNode The node will be appended as a child to this node * @param attrs any attributes * @param props Properties for the node */ createElement(tagName: VNodeType, content?: string, parentNode?: VNode, attrs?: Attribute[], props?: Props): VNode | VInputNode; /** * Creates an unmanagedNode (its childnodes are ignored by the renderer) at a specified mountpoint. * @param mount */ createUnmanagedNode(mount: VNode): VNode; /** * Creates an unmanagedNode (its childnodes are ignored by the renderer) at a specified mountpoint. This operation does not cause a re-render * @param mount */ createUnmanagedNoDirty(mount: VNode): VNode; /** * Creates a VNode, useful for cleanly modelling a DOM structure using the children array and optional nodeOptions * @param nodeName Type of the HTML tag * @param options * @param children */ k(nodeName: VNodeType, options?: NodeOptions, children?: Array<VNode>): VInputNode | VNode; /** * Adds an object into the pluginMap, retrieve it using VApp.get() * @param key key where this object is stored * @param obj */ use(key: string, obj: any): void; /** * retrieve an object saved in the app, using VApp.use() * @param key */ get<T>(key: string): T; /** * Configure the VApp to add an additional resolver for i18n strings * @param resolver */ useTranslationResolver(resolver: Resolver): void; private tick; }