UNPKG

4.01 kBTypeScriptView Raw
1import { Predicate } from '../common/common';
2import { TreeChanges } from '../transition/interface';
3import { StateObject } from '../state/stateObject';
4import { TargetState } from '../state/targetState';
5import { GetParamsFn, PathNode } from './pathNode';
6import { ViewService } from '../view/view';
7import { Param } from '../params/param';
8import { StateRegistry } from '../state';
9/**
10 * This class contains functions which convert TargetStates, Nodes and paths from one type to another.
11 */
12export declare class PathUtils {
13 /** Given a PathNode[], create an TargetState */
14 static makeTargetState(registry: StateRegistry, path: PathNode[]): TargetState;
15 static buildPath(targetState: TargetState): PathNode[];
16 /** Given a fromPath: PathNode[] and a TargetState, builds a toPath: PathNode[] */
17 static buildToPath(fromPath: PathNode[], targetState: TargetState): PathNode[];
18 /**
19 * Creates ViewConfig objects and adds to nodes.
20 *
21 * On each [[PathNode]], creates ViewConfig objects from the views: property of the node's state
22 */
23 static applyViewConfigs($view: ViewService, path: PathNode[], states: StateObject[]): void;
24 /**
25 * Given a fromPath and a toPath, returns a new to path which inherits parameters from the fromPath
26 *
27 * For a parameter in a node to be inherited from the from path:
28 * - The toPath's node must have a matching node in the fromPath (by state).
29 * - The parameter name must not be found in the toKeys parameter array.
30 *
31 * Note: the keys provided in toKeys are intended to be those param keys explicitly specified by some
32 * caller, for instance, $state.transitionTo(..., toParams). If a key was found in toParams,
33 * it is not inherited from the fromPath.
34 */
35 static inheritParams(fromPath: PathNode[], toPath: PathNode[], toKeys?: string[]): PathNode[];
36 static nonDynamicParams: (node: PathNode) => Param[];
37 /**
38 * Computes the tree changes (entering, exiting) between a fromPath and toPath.
39 */
40 static treeChanges(fromPath: PathNode[], toPath: PathNode[], reloadState: StateObject): TreeChanges;
41 /**
42 * Returns a new path which is: the subpath of the first path which matches the second path.
43 *
44 * The new path starts from root and contains any nodes that match the nodes in the second path.
45 * It stops before the first non-matching node.
46 *
47 * Nodes are compared using their state property and their parameter values.
48 * If a `paramsFn` is provided, only the [[Param]] returned by the function will be considered when comparing nodes.
49 *
50 * @param pathA the first path
51 * @param pathB the second path
52 * @param paramsFn a function which returns the parameters to consider when comparing
53 *
54 * @returns an array of PathNodes from the first path which match the nodes in the second path
55 */
56 static matching(pathA: PathNode[], pathB: PathNode[], paramsFn?: GetParamsFn): PathNode[];
57 /**
58 * Returns true if two paths are identical.
59 *
60 * @param pathA
61 * @param pathB
62 * @param paramsFn a function which returns the parameters to consider when comparing
63 * @returns true if the the states and parameter values for both paths are identical
64 */
65 static equals(pathA: PathNode[], pathB: PathNode[], paramsFn?: GetParamsFn): boolean;
66 /**
67 * Return a subpath of a path, which stops at the first matching node
68 *
69 * Given an array of nodes, returns a subset of the array starting from the first node,
70 * stopping when the first node matches the predicate.
71 *
72 * @param path a path of [[PathNode]]s
73 * @param predicate a [[Predicate]] fn that matches [[PathNode]]s
74 * @returns a subpath up to the matching node, or undefined if no match is found
75 */
76 static subPath(path: PathNode[], predicate: Predicate<PathNode>): PathNode[];
77 /** Gets the raw parameter values from a path */
78 static paramValues: (path: PathNode[]) => any;
79}