UNPKG

4.13 kBTypeScriptView Raw
1import { PolicyWhen, ResolvePolicy } from './interface';
2import { PathNode } from '../path/pathNode';
3import { Resolvable } from './resolvable';
4import { StateObject } from '../state/stateObject';
5import { Transition } from '../transition/transition';
6import { UIInjector } from '../interface';
7export declare const NATIVE_INJECTOR_TOKEN: string;
8/**
9 * Encapsulates Dependency Injection for a path of nodes
10 *
11 * UI-Router states are organized as a tree.
12 * A nested state has a path of ancestors to the root of the tree.
13 * When a state is being activated, each element in the path is wrapped as a [[PathNode]].
14 * A `PathNode` is a stateful object that holds things like parameters and resolvables for the state being activated.
15 *
16 * The ResolveContext closes over the [[PathNode]]s, and provides DI for the last node in the path.
17 */
18export declare class ResolveContext {
19 private _path;
20 _injector: UIInjector;
21 constructor(_path: PathNode[]);
22 /** Gets all the tokens found in the resolve context, de-duplicated */
23 getTokens(): any[];
24 /**
25 * Gets the Resolvable that matches the token
26 *
27 * Gets the last Resolvable that matches the token in this context, or undefined.
28 * Throws an error if it doesn't exist in the ResolveContext
29 */
30 getResolvable(token: any): Resolvable;
31 /** Returns the [[ResolvePolicy]] for the given [[Resolvable]] */
32 getPolicy(resolvable: Resolvable): ResolvePolicy;
33 /**
34 * Returns a ResolveContext that includes a portion of this one
35 *
36 * Given a state, this method creates a new ResolveContext from this one.
37 * The new context starts at the first node (root) and stops at the node for the `state` parameter.
38 *
39 * #### Why
40 *
41 * When a transition is created, the nodes in the "To Path" are injected from a ResolveContext.
42 * A ResolveContext closes over a path of [[PathNode]]s and processes the resolvables.
43 * The "To State" can inject values from its own resolvables, as well as those from all its ancestor state's (node's).
44 * This method is used to create a narrower context when injecting ancestor nodes.
45 *
46 * @example
47 * `let ABCD = new ResolveContext([A, B, C, D]);`
48 *
49 * Given a path `[A, B, C, D]`, where `A`, `B`, `C` and `D` are nodes for states `a`, `b`, `c`, `d`:
50 * When injecting `D`, `D` should have access to all resolvables from `A`, `B`, `C`, `D`.
51 * However, `B` should only be able to access resolvables from `A`, `B`.
52 *
53 * When resolving for the `B` node, first take the full "To Path" Context `[A,B,C,D]` and limit to the subpath `[A,B]`.
54 * `let AB = ABCD.subcontext(a)`
55 */
56 subContext(state: StateObject): ResolveContext;
57 /**
58 * Adds Resolvables to the node that matches the state
59 *
60 * This adds a [[Resolvable]] (generally one created on the fly; not declared on a [[StateDeclaration.resolve]] block).
61 * The resolvable is added to the node matching the `state` parameter.
62 *
63 * These new resolvables are not automatically fetched.
64 * The calling code should either fetch them, fetch something that depends on them,
65 * or rely on [[resolvePath]] being called when some state is being entered.
66 *
67 * Note: each resolvable's [[ResolvePolicy]] is merged with the state's policy, and the global default.
68 *
69 * @param newResolvables the new Resolvables
70 * @param state Used to find the node to put the resolvable on
71 */
72 addResolvables(newResolvables: Resolvable[], state: StateObject): void;
73 /**
74 * Returns a promise for an array of resolved path Element promises
75 *
76 * @param when
77 * @param trans
78 * @returns {Promise<any>|any}
79 */
80 resolvePath(when?: PolicyWhen, trans?: Transition): Promise<{
81 token: any;
82 value: any;
83 }[]>;
84 injector(): UIInjector;
85 findNode(resolvable: Resolvable): PathNode;
86 /**
87 * Gets the async dependencies of a Resolvable
88 *
89 * Given a Resolvable, returns its dependencies as a Resolvable[]
90 */
91 getDependencies(resolvable: Resolvable): Resolvable[];
92}