@player-ui/player
Version:
73 lines • 3.39 kB
TypeScript
import { SyncWaterfallHook, SyncHook } from "tapable-ts";
import type { BindingInstance } from "../../binding";
import type { Node } from "../parser";
import type { Resolve } from "./types";
export * from "./types";
export * from "./utils";
interface NodeUpdate extends Resolve.ResolvedNode {
/** A flag to track if a node has changed since the last resolution */
updated: boolean;
}
/**
* The Resolver is the way to take a parsed AST graph of a view and resolve it to a concrete representation of the current user state
* It combines the ability to mutate ast nodes before resolving, as well as the mutating the resolved objects while parsing
*/
export declare class Resolver {
readonly hooks: {
/** A hook to allow skipping of the resolution tree for a specific node */
skipResolve: SyncWaterfallHook<[boolean, Node.Node, Resolve.NodeResolveOptions], Record<string, any>>;
/** An event emitted before calculating the next update */
beforeUpdate: SyncHook<[Set<BindingInstance> | undefined], Record<string, any>>;
/** An event emitted after calculating the next update */
afterUpdate: SyncHook<[any], Record<string, any>>;
/** The options passed to a node to resolve it to an object */
resolveOptions: SyncWaterfallHook<[Resolve.NodeResolveOptions, Node.Node], Record<string, any>>;
/** A hook to transform the AST node into a new AST node before resolving it */
beforeResolve: SyncWaterfallHook<[Node.Node | null, Resolve.NodeResolveOptions], Record<string, any>>;
/**
* A hook to transform an AST node into it's resolved value.
* This runs _before_ any children are resolved
*/
resolve: SyncWaterfallHook<[any, Node.Node, Resolve.NodeResolveOptions], Record<string, any>>;
/**
* A hook to transform the resolved value of an AST node.
* This runs _after_ all children nodes are resolved
*/
afterResolve: SyncWaterfallHook<[any, Node.Node, Resolve.NodeResolveOptions], Record<string, any>>;
/** Called at the very end of a node's tree being updated */
afterNodeUpdate: SyncHook<[Node.Node, Node.Node | undefined, NodeUpdate], Record<string, any>>;
};
/**
* The AST tree after beforeResolve is ran mapped to the AST before beforeResolve is ran
*/
private readonly ASTMap;
/**
* The root node in the AST tree we want to resolve
*/
readonly root: Node.Node;
/**
* The cache of the last resolved values when walking the tree.
* This gets recycled every update to avoid stale data if a node is unused in an update
*/
private resolveCache;
/**
* Cache of node IDs that have been processed to track if nodes have duplicate IDs
*/
private idCache;
/**
* The parameters required to resolve AST nodes
*/
private readonly options;
/**
* Tapable logger for logging errors encountered during view resolution
*/
private logger?;
constructor(root: Node.Node, options: Resolve.ResolverOptions);
getSourceNode(convertedAST: Node.Node): Node.Node | undefined;
update(changes?: Set<BindingInstance>): any;
getResolveCache(): Map<Node.Node, Resolve.ResolvedNode>;
private getPreviousResult;
private cloneNode;
private computeTree;
}
//# sourceMappingURL=index.d.ts.map