UNPKG

alien-dom

Version:

Next-generation JSX client renderer with observable data primitives, immediate DOM references, and more.

86 lines (82 loc) 3.96 kB
import { J as JSX, bq as AnyDeferredNode, f as FunctionComponent, af as Observer, x as ContextStore, a3 as AlienEffects, p as ReadonlyRef } from './animate-b617067e.js'; import './jsx-runtime-1947324d.js'; /** * A "node store" is responsible for memoization of DOM nodes by their JSX * element keys. It also stores any pending updates to existing DOM nodes. */ interface NodeStore { getNodeForKey: (key: JSX.ElementKey) => ChildNode | DocumentFragment | undefined; setNodeForKey: (key: JSX.ElementKey, node: ChildNode | DocumentFragment) => void; getNodeUpdateForKey: (key: JSX.ElementKey) => AnyDeferredNode | undefined; setNodeUpdateForKey: (key: JSX.ElementKey, update: AnyDeferredNode) => void; } type ElementRefs = Map<JSX.ElementKey, ChildNode | DocumentFragment>; /** Internal state for a component instance. */ declare class AlienComponent<Props extends object = any> extends Observer implements NodeStore { readonly tag: (props: Props) => JSX.ChildrenProp; readonly parent: AlienComponent | null; readonly context: ContextStore; readonly props: Props; hooks: any[]; nextHookIndex: number; rootNode: ChildNode | DocumentFragment | null; rootNodeCallbacks: Set<(node: ChildNode | DocumentFragment) => void> | null; rootKey: JSX.ElementKey | undefined; /** Deferred nodes (by key) created in the current render pass. */ updates: Map<JSX.ElementKey, AnyDeferredNode> | null; /** Stable references to the nodes that are mounted. */ nodes: ElementRefs | null; /** Stable references that were added or reused by the current render pass. */ newNodes: ElementRefs | null; /** Effects tied to the last finished render pass. */ effects: AlienEffects | null; /** Effects added in the current render pass. */ newEffects: AlienEffects | null; /** Values memoized in the last finished render pass. */ memos: Map<any, any> | null; /** Values memoized in the current render pass. */ newMemos: Map<any, any> | null; constructor(tag: (props: Props) => JSX.ChildrenProp, initialProps: Props); get firstChild(): ChildNode | null; get lastChild(): ChildNode | null; get ownerDocument(): Document | null | undefined; patchProps(newProps: Partial<Props>): void; replaceProps(newProps: Props): void; truncate(length: number): void; setRootNode(rootNode: ChildNode | DocumentFragment): void; getNodeForKey(key: JSX.ElementKey): ChildNode | DocumentFragment | undefined; setNodeForKey(key: JSX.ElementKey, node: ChildNode | DocumentFragment): void; getNodeUpdateForKey(key: JSX.ElementKey): AnyDeferredNode | undefined; setNodeUpdateForKey(key: JSX.ElementKey, update: AnyDeferredNode): void; nextCompute(): void; isObservablyPure(): boolean; didObserve(ref: ReadonlyRef): void; /** * Note: This doesn't remove the root node from its document. */ dispose(): void; } interface AlienComponent { readonly name: string; } /** * @internal * The compiler inserts `registerMemo` calls for props with an inlined object, * array, or function call as its value. */ declare function registerMemo(key: string, value: any, deps?: readonly any[] | false): any; /** * @internal * Like `registerMemo` but for inlined callback props. */ declare function registerCallback(key: string, callback: Function, deps?: readonly any[] | false): Function; /** * @internal * This swaps out nested components with a stable reference so that * elements created with it can be reused even if the parent component * is re-rendered. The nested component is wrapped so it can be updated * when the parent component re-renders, thereby avoiding stale closure * issues. */ declare function registerNestedTag(key: string, tag: FunctionComponent, deps: readonly any[]): FunctionComponent; export { AlienComponent as A, NodeStore as N, registerMemo as a, registerNestedTag as b, registerCallback as r };