UNPKG

reblendjs

Version:

This is build using react way of handling dom but with web components

117 lines (116 loc) 6.21 kB
import { ReblendTyping } from 'reblend-typing'; export declare class NodeOperationUtil { /** * Detaches the given node from the DOM. * If the node is a primitive, the function returns immediately. * If the node has a `disconnectedCallback`, it will be invoked. * Otherwise, it will be removed from the DOM. * * @param {ReblendTyping.Component<P, S> | HTMLElement} node - The node to detach. */ static detach<P, S>(node: ReblendTyping.Component<P, S> | HTMLElement): void; /** * Detaches all child nodes and HTML elements from the given `ReblendTyping.Component<P, S>`. * If the node is a primitive, the function returns immediately. * * @param {ReblendTyping.Component<P, S>} node - The parent node from which children will be detached. */ static detachChildren<P, S>(node: ReblendTyping.Component<P, S>): void; /** * Calls `connectedCallback` on the node if it exists, signaling that the node has been connected to the DOM. * * @template T * @param {T | undefined} node - The node to connect. */ static connected<P, S, T extends ReblendTyping.Component<P, S> | HTMLElement>(node: T | undefined): void; /** * Replaces the old node with a new node or nodes. * Handles scenarios where old and new nodes may be React-based or standard HTML. * * @param {ReblendTyping.Component<P, S> | ReblendTyping.Component<P, S>[]} newNode - The new node(s) to replace the old node. * @param {ReblendTyping.Component<P, S>} oldNode - The old node to be replaced. */ static replaceOldNode<P, S>(newNode: ReblendTyping.Component<P, S> | ReblendTyping.Component<P, S>[], oldNode: ReblendTyping.Component<P, S>): void; /** * Creates patches to create or remove nodes by comparing oldNode and newNode. * * @param {ReblendTyping.Component<P, S>} parent - The parent node. * @param {ReblendTyping.DomNodeChild} oldNode - The old node. * @param {ReblendTyping.VNodeChild} newNode - The new node. * @returns {ReblendTyping.Patch[]} - The array of patches. */ static diffCreateOrRemove<P, S>(parent: ReblendTyping.Component<P, S>, oldNode: ReblendTyping.DomNodeChild<P, S>, newNode: ReblendTyping.VNodeChild): ReblendTyping.Patch<P, S>[]; /** * Diffs oldNode and newNode to generate patches that represent the changes between them. * * @param {ReblendTyping.Component<P, S>} parent - The parent node. * @param {ReblendTyping.DomNodeChild} oldNode - The old node. * @param {ReblendTyping.VNodeChild} newNode - The new node. * @returns {ReblendTyping.Patch[]} - The array of patches. */ static diff<P, S>(parent: ReblendTyping.Component<P, S>, oldNode: ReblendTyping.DomNodeChild<P, S>, newNode: ReblendTyping.VNodeChild): ReblendTyping.Patch<P, S>[]; /** * Diffs the props of the newNode and oldNode to generate a list of prop changes. * * @param {VNode} newNode - The new virtual node. * @param {ReblendTyping.Component<P, S>} oldNode - The old base component node. * @returns {any[]} - The array of property differences. */ static diffProps<P, S>(newNode: ReblendTyping.VNode, oldNode: ReblendTyping.Component<P, S>): ReblendTyping.PropPatch<P, S>[]; /** * Compares two values for deep equality using an iterative approach to avoid stack overflow issues with large objects. * This function handles circular references and ignores properties named 'ref'. * It also ignores instances of `HTMLElement` if they exist in both objects. * * @param a - The first value to compare. * @param b - The second value to compare. * @returns `true` if the values are deeply equal, `false` otherwise. */ static deepEqualIterative(a: any, b: any): boolean; /** * Performs a deep comparison between two objects, including functions. * * @param {*} firstObject - The first object or function to compare. * @param {*} secondObject - The second object or function to compare. * @returns {boolean} - True if the objects are deeply equal, otherwise false. */ static deepCompare(firstObject: any, secondObject: any): boolean; /** * Diffs the children of the old and new virtual nodes and returns the patches required to update them. * * @param {ReblendTyping.Component<P, S>} parent - The parent component containing the children. * @param {ReblendTyping.Component<P, S>} oldNode - The old component node. * @param {VNode} newNode - The new virtual node. * @returns {Patch[]} - An array of patches representing the differences between the old and new children. */ static diffChildren<P, S>(parent: ReblendTyping.Component<P, S>, oldNode: ReblendTyping.Component<P, S>, newNode: ReblendTyping.VNode): ReblendTyping.Patch<P, S>[]; /** * Applies an array of patches to the component. * * @param {Patch[]} patches - The array of patches to apply. */ static applyPatches<P, S>(patches: ReblendTyping.Patch<P, S>[]): Promise<void>; /** * Asynchronously applies property patches to nodes. * * @param {PropPatch[]} [patches] - The property patches to apply. */ static applyProps<P, S>(patches?: ReblendTyping.PropPatch<P, S>[]): Promise<void>; /** * Performs a replacement operation on an old node. * * @param {ReblendTyping.Component<P, S>} oldNode - The old node to replace. * @param {() => void} operation - The operation to execute for the replacement. */ static replaceOperation<P, S>(oldNode: ReblendTyping.Component<P, S>, operation: () => Promise<void>): void; /** * Callback invoked when the component is connected to the DOM. */ static connectedCallback<P, S>(thiz: ReblendTyping.Component<P, S>): void; /** * Lifecycle method called when the component is disconnected from the DOM. * Cleans up resources and removes the component from its parent. * Uses bruteforce approach insuring that there is not memory leakage */ static disconnectedCallback<P, S>(thiz: ReblendTyping.Component<P, S>, fromCleanUp?: boolean): void; }