preact-reconciler
Version:
Custom renderers for Preact in <1KB.
58 lines (57 loc) • 3.15 kB
TypeScript
import { type VNode, type Component, type ComponentChildren, type ComponentChild } from 'preact';
interface FiberNode<T = any> extends HTMLElement {
ownerSVGElement?: null;
fiber?: Fiber;
containerInfo: T;
hostConfig: HostConfig;
}
export interface Fiber<P = any, I = any, R = any> extends VNode<P> {
__c?: Component & {
__P: FiberNode<R>;
};
__e: FiberNode<R>;
__: Fiber;
__type?: string;
stateNode?: I;
type: string;
container: FiberNode<R>;
props: P & {
children: ComponentChildren;
};
memoizedProps?: P & {
children: ComponentChildren;
};
refCleanup: null | (() => void);
sibling: Fiber | null;
flags: number;
}
export interface HostConfig<Type = string, Props = Record<string, any>, Container = any, Instance = any, TextInstance = any, PublicInstance = any, HostContext = any, UpdatePayload = any> {
createInstance(type: Type, props: Props, rootContainer: Container, hostContext: HostContext, internalHandle: Fiber<Props, Instance, Container>): Instance;
finalizeInitialChildren(instance: Instance, type: Type, props: Props, rootContainer: Container, hostContext: HostContext): boolean;
prepareUpdate?(instance: Instance, type: Type, oldProps: Props, newProps: Props, rootContainer: Container, hostContext: HostContext): UpdatePayload | null;
getPublicInstance(instance: Instance | TextInstance): PublicInstance;
appendChild?(parent: Instance, child: Instance | TextInstance): void;
appendChildToContainer?(container: Container, child: Instance | TextInstance): void;
insertBefore?(parent: Instance, child: Instance | TextInstance, beforeChild: Instance | TextInstance): void;
insertInContainerBefore?(container: Container, child: Instance | TextInstance, beforeChild: Instance | TextInstance): void;
removeChild?(parent: Instance, child: Instance | TextInstance): void;
removeChildFromContainer?(container: Container, child: Instance | TextInstance): void;
commitMount?(instance: Instance, type: Type, props: Props, internalHandle: Fiber<Props, Instance, Container>): void;
commitUpdate?(instance: Instance, updatePayload: UpdatePayload, type: Type, prevProps: Props, nextProps: Props, internalHandle: Fiber<Props, Instance, Container>): void;
commitUpdate?(instance: Instance, type: Type, prevProps: Props, nextProps: Props, internalHandle: Fiber<Props, Instance, Container>): void;
[name: string]: unknown;
}
declare class FiberNode extends HTMLElement {
setAttribute(name: string, value: any): void;
appendChild<T extends Node>(node: T): T;
insertBefore<T extends Node>(node: T, beforeNode: Node | null): T;
removeChild<T extends Node>(node: T): T;
}
export interface Reconciler {
createContainer<T>(containerInfo: T): FiberNode<T>;
updateContainer<T>(element: ComponentChild, container: FiberNode<T>): void;
createPortal(children: ComponentChild, containerInfo: any, implementation: any, key?: string | null): void;
injectIntoDevTools(devToolsConfig: any): any;
}
declare const _default: (hostConfig: HostConfig) => Reconciler;
export default _default;